我有一个关于在 JUnit 中分组测试的问题。
我有一个带有注释的测试类
@Category(IntegrationTests.class)
public class TestClass { ... }
而IntegrationTests 只是一个接口。
无论如何我可以在仅运行此类测试的maven命令行中指定吗?
非常感谢。
我有一个关于在 JUnit 中分组测试的问题。
我有一个带有注释的测试类
@Category(IntegrationTests.class)
public class TestClass { ... }
而IntegrationTests 只是一个接口。
无论如何我可以在仅运行此类测试的maven命令行中指定吗?
非常感谢。
单元测试和集成测试之间的区别很简单,命名约定:
**/Test*.java
**/*Test.java
**/*TestCase.java
将被识别为单元测试。并且基于maven-failsafe-plugin的集成测试将被不同的命名约定识别:
**/IT*.java
**/*IT.java
**/*ITCase.java
为什么不依赖现有的约定?
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 Plugin 将自动包含所有具有以下通配符模式的测试类:
"**/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".