如何使用 Maven surefire 排除给定类别的所有 JUnit4 测试? [英] How to exclude all JUnit4 tests with a given category using Maven surefire?
问题描述
我打算用@Category 注释来注释我的一些 JUnit4 测试.然后,我想从在我的 Maven 构建上运行的测试类别中排除.
我从 Maven 文档中看到,可以指定要运行的测试类别.我想知道如何指定不运行的测试类别.
谢谢!
您可以这样做:
您的 pom.xml 应包含以下设置.
<预><代码><配置><排除><exclude>**/TestCircle.java</exclude><exclude>**/TestSquare.java</exclude></排除></配置>如果您想要正则表达式支持,请使用
<exclude>%regex[.*[Cat|Dog].*Test.*]</exclude></排除>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
如果要使用Category注解,需要做如下操作:
@Category(com.myproject.annotations.Exclude)@测试公共 testFoo() {....}
在你的 maven 配置中,你可以有这样的东西
<预><代码><配置><excludedGroups>com.myproject.annotations.Exclude</excludedGroups></配置>I intend on annotating some of my JUnit4 tests with an @Category annotation. I would then like to exclude that category of tests from running on my Maven builds.
I see from the Maven documentation that it is possible to specify a category of tests to run. I want to know how to specify a category of tests not to run.
Thanks!
You can do this as follows:
Your pom.xml should contain the following setup.
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
If you want regex support just use
<excludes>
<exclude>%regex[.*[Cat|Dog].*Test.*]</exclude>
</excludes>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
If you want to use Category annotation, you need to do the following:
@Category(com.myproject.annotations.Exclude)
@Test
public testFoo() {
....
}
In your maven configuration, you can have something like this
<configuration>
<excludedGroups>com.myproject.annotations.Exclude</excludedGroups>
</configuration>
这篇关于如何使用 Maven surefire 排除给定类别的所有 JUnit4 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!