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-bin\apache-maven-3.3.1

  MAVEN: %MAVEN_HOME%\bin

  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.

转载于:https://www.cnblogs.com/wuditju/p/4460037.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值