Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude all JUnit4 tests with a given category using Maven surefire?

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.

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.

Thanks!

like image 200
Adam Avatar asked Jan 03 '13 02:01

Adam


1 Answers

You can do this as follows:

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

In your maven configuration, you can have something like this

<configuration>
  <excludedGroups>com.myproject.annotations.Exclude</excludedGroups>
</configuration>
like image 87
Kartik Avatar answered Sep 22 '22 14:09

Kartik