如何使用Maven surefire排除给定类别的所有JUnit4测试? [英] How to exclude all JUnit4 tests with a given category using Maven surefire?

查看:322
本文介绍了如何使用Maven surefire排除给定类别的所有JUnit4测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

Maven文档中可以看到,指定要运行的测试类别.我想知道如何指定要运行的测试类别.

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.

谢谢!

推荐答案

您可以执行以下操作:

您的pom.xml应包含以下设置.

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() {
   ....
}

在您的Maven配置中,您可以拥有类似的内容

In your maven configuration, you can have something like this

<configuration>
  <excludedGroups>com.myproject.annotations.Exclude</excludedGroups>
</configuration>

这篇关于如何使用Maven surefire排除给定类别的所有JUnit4测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆