When running "mvn test" in command line, there is a warning message "skip non existing resourceDirectory" and cannot run test cases.
Refer to http://rongjih.blog.163.com/blog/static/335744612010102911363452/
maven是使用surefire插件执行测试的,它按照指定格式的类名来查找匹配的测试类,
默认包含的测试类:
- **/*Test.java
- **/Test*.java
- **/*TestCase.java
默认排除的测试类:
- **/Abstract*Test.java
- **/Abstract*TestCase.java
因此默认情况下“**/*Tests.java”是不会被mvn test发现并执行的,可按如下修改surefire插件的配置以达到包含"**/*Tests.java"测试类的目的:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/Abstract*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
运行指定的测试类:
>mvn test -Dtest=[ClassName]
[ClassName]为要运行的测试类的类名(不要带扩展名),多个测试类间用逗号连接即可,类名支持*通配符,范例:
1) >mvn test -Dtest=MyClassTest
2) >mvn test -Dtest=MyClass1Test,MyClass2Test
3) >mvn test -Dtest=MyClass*Test,YourClassTest
4) >mvn test -Dtest=MyClassTest
运行测试类中指定的方法:(这个需要maven-surefire-plugin:2.7.3以上版本才能支持)
>mvn test -Dtest=[ClassName]#[MethodName]
[MethodName]为要运行的方法名,支持*通配符,范例:
1) >mvn test -Dtest=MyClassTest#test1
2) >mvn test -Dtest=MyClassTest#*test*