如何使用Maven排除给定类别的所有JUnit4测试



我打算用@Category注释注释我的一些JUnit4测试。然后,我想从我的Maven构建中排除这类测试。

我从Maven文档中看到,可以指定一个测试类别来运行。我想知道如何指定一个类别的测试而不是运行。

谢谢!

您可以这样做:

您的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>

最新更新