【发布时间】:2012-12-17 10:01:35
【问题描述】:
我打算用@Category 注释来注释我的一些JUnit4 测试。然后,我想排除在我的 Maven 构建上运行的那类测试。
我从Maven documentation 中看到,可以指定一个测试类别 运行。我想知道如何指定要运行的测试类别不。
谢谢!
【问题讨论】:
标签: junit maven-2 junit4 maven-surefire-plugin
我打算用@Category 注释来注释我的一些JUnit4 测试。然后,我想排除在我的 Maven 构建上运行的那类测试。
我从Maven documentation 中看到,可以指定一个测试类别 运行。我想知道如何指定要运行的测试类别不。
谢谢!
【问题讨论】:
标签: junit maven-2 junit4 maven-surefire-plugin
你可以这样做:
您的 pom.xml 应包含以下设置。
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
如果您想要正则表达式支持,请使用
<excludes>
<exclude>%regex[.*[Cat|Dog].*Test.*]</exclude>
</excludes>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
如果要使用Category注解,需要进行如下操作:
@Category(com.myproject.annotations.Exclude)
@Test
public testFoo() {
....
}
在你的 maven 配置中,你可以有这样的东西
<configuration>
<excludedGroups>com.myproject.annotations.Exclude</excludedGroups>
</configuration>
【讨论】:
excludedGroups 的东西