我有一个关于在JUnit中对测试进行分组的问题。
我有一个用
注释的测试类@Category(IntegrationTests.class)
public class TestClass { ... }
IntegrationTests只是一个界面。
无论如何,我可以在maven命令行中指定只运行此类测试吗?
非常感谢。
答案 0 :(得分:4)
单元测试和集成测试之间的区别很简单naming convention:
**/Test*.java
**/*Test.java
**/*TestCase.java
将被视为单元测试。基于maven-failsafe-plugin的集成测试将通过不同的命名约定来识别:
**/IT*.java
**/*IT.java
**/*ITCase.java
答案 1 :(得分:2)
为什么不依赖现有的惯例?
mvn clean test
将通过surefire运行单元测试。
mvn clean verify
将通过故障安全
您可以使用命名约定或注释来强制选择。
thisIsAUnitTest.java will be executed by surefire (mvn test)
thisClassIsAnIT.java will be executed by failsafe (mvn verify)
怎么样?!
默认情况下,Surefire插件会自动包含具有以下通配符模式的所有测试类:
"**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test".
"**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase".
默认情况下,Failsafe插件会自动包含具有以下通配符模式的所有测试类:
"**/IT*.java" - includes all of its subdirectories and all java filenames that start with "IT".
"**/*IT.java" - includes all of its subdirectories and all java filenames that end with "IT".
"**/*ITCase.java" - includes all of its subdirectories and all java filenames that end with "ITCase".