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

3

37

Something like the following.

I would like a way to skip my dao tests in surefire. Trying to avoid overhead of defining Suites.

With CI I'd like to have one nightly that runs all tests and another 5 minute poll of SCM that runs only 'fast' tests.

mvn -DskipPattern=**.dao.** test
Yea answered 8/12, 2010 at 16:24 Comment(0)
R
55

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.

Rockett answered 17/12, 2010 at 18:19 Comment(0)
E
27

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:

(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)

Expound answered 8/12, 2010 at 16:54 Comment(1)
6 years later and surefire.excludes still doesn't work at the command line.Paulo
O
8

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.

Oberheim answered 11/10, 2017 at 19:50 Comment(2)
To you have a documentation reference for this mechanism?Smokestack
@Smokestack maven.apache.org/surefire/maven-surefire-plugin/examples/…Besom

© 2022 - 2024 — McMap. All rights reserved.