mavenunit-testingjunitmaven-surefire-plugin

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


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?


Solution

  • It's 2023 and the answer is: You can.

    With with property excludesFile, you can refer to a file which contains exclude patterns, and as docs say,

    Since 3.0.0-M6, method filtering support is provided in the exclusions file as well, example

    file excludedTests.txt:

    pkg.SomeTest#testMethod
    

    So for example in the <configuration> section you need to add

    <configuration>
      <excludesFile>excludedTests.txt</excludesFile>
    </configuration>
    

    and during execution, the testMethod is not invoked.