Maven Disable Tests

In this tutorial we will look at how to disable tests with maven. As part of the build and packaging process Maven can run execute your Junit Tests. However, this behavior can be disabled.

How To Disable Tests For A Project

To disable tests for a project you can use the skipTests property of the surefire plugin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<properties>
    <skipTests>false</skipTests>
</properties>
<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <skipTests>${skipTests}</skipTests>
        </configuration>
      </plugin>
    </plugins>
</build>

Above we use a property called skipTests and use this property as the value of the surefire maven plugin configuration element.

We can then pass this property on the command line to decide if we wish to disable or enable tests as part of a build.

1
mvn install -DskipTests=True

Conclusion

In this short tutorial we looked at how to disable tests with maven. We saw that we can use maven to disable tests both from the build file and the command line.