Inclusions and Exclusions of Tests
Inclusions
By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:
- "**/IT*.java" - includes all of its subdirectories and all java filenames that start with "IT".
- "**/*IT.java" - includes all of its subdirectories and all java filenames that end with "IT".
- "**/*ITCase.java" - includes all of its subdirectories and all java filenames that end with "ITCase".
If the test classes does not go with the naming convention, then configure Failsafe Plugin and specify the tests you want to include.
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.11</version> <configuration> <includes> <include>Sample.java</include> </includes> </configuration> </plugin> </plugins> </build> [...] </project>
Exclusions
There are certain times when some tests are causing the build to fail. Excluding them is one of the best workarounds to continue the build. Exclusions can be done by configuring the excludes property of the plugin.
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.11</version> <configuration> <excludes> <exclude>**/CircleIT.java</exclude> <exclude>**/SquareIT.java</exclude> </excludes> </configuration> </plugin> </plugins> </build> [...] </project>
Regular expression support
An include/exclude pattern can be an ant-style path expression, but regular expressions are also supported through this syntax:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.11</version> <configuration> <includes> <include>%regex[.*[Cat|Dog].*Test.*]</include> </includes> </configuration> </plugin> </plugins> </build> [...] </project>
Note the syntax %regex[expr], where expr is the actual expression and the rest is just wrapping. Also note that regex matches are done over .class files and not .java files.