Maven中使用Junit测试

在src\test\java中编写测试程序,会出现提示找不到junit.jar包:

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class HelloTest {
   @Test
   public void testHello(){
      App app=new App();
      String result=app.sayHello();
      assertEquals("Hello",result);
   }
}

出现问题的原因:在pom.xml中默认生成:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

  junit
  junit
  3.8.1
  test

1
2
3
4
5
6
因为3.x版本为编程方式,而4.x是注解方式。本次测试使用注解方式,故应该修改如下:

   
      junit
      junit
      4.7
      test
   

1
2
3
4
5
6
maven中主要命令: 
mvn clean compile:编译; 
mvn clean test:测试; 
mvn clean package:打包,默认jar格式 
mvn clean install:打包到本地仓库
 

你可能感兴趣的:(Maven)