5

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.

My question is: Is there a way using surefire to exclude tests at a test method level - not a class level?

Tunaki
  • 125,519
  • 44
  • 317
  • 399
hawkeye
  • 33,004
  • 28
  • 141
  • 288

2 Answers2

2

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>
question_maven_com
  • 2,263
  • 14
  • 19
1

I don't think there is an option for that - not even a hidden one. JUnit itself gets a list of files it should scan for test execution. See JUnitCore.

The surefire plugin allows to distinguish tests in groups. See also this answer on Stackoverflow and this Blog.

That might be an option?

Community
  • 1
  • 1
wemu
  • 7,582
  • 3
  • 31
  • 54