zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    590. N-ary Tree Postorder Traversal
    C++——指针3
    C++——指针2-指向数组的指针和指针数组
    C++——指针1
    C++——二维数组和对象数组
    C++——一维数组
    C++——程序的结构
    C++——类与对象
    C++——函数
    C++——简单程序设计
  • 原文地址:https://www.cnblogs.com/wuditju/p/4460037.html
Copyright © 2011-2022 走看看