Is there a way to tell surefire to skip tests in a certain package?

Solution 1:

Let me extend Sean's answer. This is what you set in pom.xml:

<properties>
  <exclude.tests>nothing-to-exclude</exclude.tests>
</properties>
<profiles>
  <profile>
    <id>fast</id>
    <properties>
      <exclude.tests>**/*Dao*.java</exclude.tests>
    </properties>
  </profile>
</profiles>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <excludes>
     <exclude>${exclude.tests}</exclude>
    </excludes>
  </configuration>
</plugin>

Then in CI you start them like this:

mvn -Pfast test

That's it.

Solution 2:

Sure, no problem:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.6</version>
   <configuration>
      <excludes>
         <!-- classes that include the name Dao -->
         <exclude>**/*Dao*.java</exclude>
         <!-- classes in a package whose last segment is named dao -->
         <exclude>**/dao/*.java</exclude>
      </excludes>
   </configuration>
</plugin>

Reference:

  • Maven Surefire Plugin > Inclusions and Exclusions of Tests

(The excludes can not be configured via command line, so if you want to turn this behavior on conditionally, you will have to define a profile and activate that on the command line)

Solution 3:

It is possible to exclude tests using the commandline; using ! to exclude.

Note: I'm not sure but possibly needs 2.19.1 or later version of surefire to work.

Examples:

This will not run TestHCatLoaderEncryption

mvn install '-Dtest=!TestHCatLoaderEncryption'

Exclude a package:

mvn install '-Dtest=!org.apache.hadoop.**'

This can be combined with positive filters as well. The following will run 0 tests:

mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption'

See the Maven Surefire docs.