在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
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
1
2
3
4
5
6
因为3.x版本为编程方式,而4.x是注解方式。本次测试使用注解方式,故应该修改如下:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
1
2
3
4
5
6
maven中主要命令:
mvn clean compile:编译;
mvn clean test:测试;
mvn clean package:打包,默认jar格式
mvn clean install:打包到本地仓库