【问题标题】:How to exclude all JUnit4 tests with a given category using Maven surefire?如何使用 Maven surefire 排除具有给定类别的所有 JUnit4 测试?
【发布时间】:2012-12-17 10:01:35
【问题描述】:

我打算用@Category 注释来注释我的一些JUnit4 测试。然后,我想排除在我的 Maven 构建上运行的那类测试。

我从Maven documentation 中看到,可以指定一个测试类别 运行。我想知道如何指定要运行的测试类别

谢谢!

【问题讨论】:

    标签: junit maven-2 junit4 maven-surefire-plugin


    【解决方案1】:

    你可以这样做:

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

    【讨论】:

    猜你喜欢
    • 2019-11-20
    • 2018-10-10
    • 2017-09-28
    • 1970-01-01
    • 2014-11-08
    • 2014-08-08
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    相关资源
    最近更新 更多