有没有一种方法可以使用surefire排除测试方法级别(而不是类级别)的测试? [英] Is there a way using surefire to exclude tests at a test method level - not a class level?

查看:88
本文介绍了有没有一种方法可以使用surefire排除测试方法级别(而不是类级别)的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache Maven Surefire网站具有以下示例语法可将测试排除在运行范围之外:

The Apache Maven Surefire site has the following example syntax to exclude tests from running:

<configuration>
  <excludes>
    <exclude>**/TestCircle.java</exclude>
    <exclude>**/TestSquare.java</exclude>
  </excludes>
</configuration>

这将排除类,但是如果您要排除的测试是在具有其他一系列测试的类中,则该类中的每个测试都将被排除,无论您是否只想排除一个测试.

This excludes classes, but if the test you want to exclude was in a class with a bunch of other tests - then every test in the class will be excluded, regardless of whether you only wanted to exclude the one test or not.

这似乎不太细致.我想从具有多个测试的类中仅排除一个测试.

This doesn't seem very granular. I'd like to exclude just one test from a class that has multiple tests.

我的问题是:是否可以使用surefire排除测试方法级别(而不是类级别)的测试?

推荐答案

使用JUnit> = 4.8和Categories => http://maven.apache.org/surefire/maven-surefire -plugin/examples/junit.html

Use JUnit >= 4.8 and Categories => http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html

1. Add : public interface SlowTests{} 

2.  public class AppTest {
      @Test
      @Category(com.mycompany.SlowTests.class)
      public void testSlow1() {
        System.out.println("testSlow1");
      }

      @Test
      @Category(com.mycompany.SlowTests.class)
      public void testSlow2() {
        System.out.println("testSlow2");
      }

      @Test 
      public void test3() {
        System.out.println("test3");
      }

        @Test 
      public void test4() {
        System.out.println("test4");
      }
    }

3.
 <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.11</version>
      <configuration>
        <groups>com.mycompany.SlowTests</groups>
      </configuration>
    </plugin>

这篇关于有没有一种方法可以使用surefire排除测试方法级别(而不是类级别)的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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