Search code examples
mavenunit-testingmaven-surefire-pluginmaven-failsafe-plugin

How to skip surefire tests but run failsafe tests?


In my project I have surefire as well as failsafe tests.

If I run with mvn clean install -DskipTests then both kinds of tests are skipped.

If I try to run a single failsafe test using -Dit.test=TestName then first all surefire tests run and then my it test.. but as the surefire tests take a long time this is not good.

I would like to skip the surefire tests in some cases but run the failsafe IT tests.


Solution

  • It's sometimes kind of confusing (annoying?) that, by default, -DskipITs=true will skip Failsafe but -DskipTests=true will skip both Surefire and Failsafe tests.

    Anyway, you can change this behaviour by configuring the Surefire plugin to use a different 'skip' parameter. For example:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <configuration>
            <skip>${skipSurefire}</skip>
        </configuration>
    </plugin>
    

    This will allow you to skip Surefire tests but not Failsafe tests by invoking:

    mvn clean verify -DskipSurefire=true