• SPM——Using Maven+Junit to test Hello Wudi


      Last week, ours teacher taught us 'Software Delivery and Build Management'. And in this class, our teachers gave us a task about Develop the project “HelloWorld” and Install Maven and Build the “HelloWorld” Project. So I want to write something about using Maven and Junit.

      1.Download Maven and configure environment variables

      

      MAVEN_HOME: D:apache-maven-3.3.1-binapache-maven-3.3.1

      MAVEN: %MAVEN_HOME%in

      PATH:%MAVEN%;

      Then use cmd command 'mvn -v' to check the environment variables.

      

      2.Using maven create your own project

      

      After running this command, you will find that in the directory of C:/user/Anonymous, you have created your own project.

      my-app-simple
      |-- pom.xml
        `-- src
        |-- main
        |   `-- java
        |       `-- com
        |           `-- mycompany
        |               `-- app
        |                   `-- App.java
        `-- test
           `-- java
              `-- com
                         `-- mycompany
                            `-- app
                                `-- AppTest.java

      3.Compile, test and package

      

      This is compile command.

      

      

      This is test command.

      

      

      This is package command.

      4.Import your project into Eclipse

      

      Window->Preferences->Maven->Installations

      Then add your maven into the Eclipse.

      Import->Others->Maven->Existing Maven Projects

      

      

      

      5.Download Junit and configure it

      

      6.Write your own project code and test code

      In App.java

      

    package com.mycompany.app;
    
    /**
     * Hello world!
     *
     */
    public class App 
    {
    	public String sayApp() { 
    		return "Hello Wudi!"; 
    	} 
    	
    	
        public static void main( String[] args )
        {
        	App app = new App();
            System.out.println( "Hello Wudi!" );
        }
    }
    

      In AppTest.java

    package com.mycompany.app;
    
    import junit.framework.Test;
    import junit.framework.TestCase;
    import junit.framework.TestSuite;
    
    /**
     * Unit test for simple App.
     */
    public class AppTest 
        extends TestCase
    {
        /**
         * Create the test case
         *
         * @param testName name of the test case
         */
        public AppTest( String testName )
        {
            super( testName );
        }
    
        /**
         * @return the suite of tests being tested
         */
        public static Test suite()
        {
            return new TestSuite( AppTest.class );
        }
    
        /**
         * Rigourous Test :-)
         */
        public void testApp()
        {
        	
        	App app = new com.mycompany.app.App(); 
        	assertEquals("Hello Wudi!", app.sayApp() );
        }
    }
    

      Then you can run your project and get what you want.

      

      

      That's all.

      To be professional.

  • 相关阅读:
    delphi for xx in xx do 语法的使用示例
    Delphi XE7的安卓程序如何调用JAVA的JAR,使用JAVA的类?
    ST Visual Programmer批量烧写教程
    关于FATFS文件系统挂载多个磁盘
    STM8不用手动复位进入自带Bootloader方法(串口下载)
    Linux下安装Eclipse
    微信平台二次开发实例讲解——三元篇
    架构设计深入学习01--概论与预架构阶段
    Linux tomcat安装详解
    程序员的自我修养——操作系统篇
  • 原文地址:https://www.cnblogs.com/wuditju/p/4460037.html
Copyright © 2020-2023  润新知