Home Maven Maven - skip tests?

Maven – skip tests?

In this quick guide, we discuss several use cases on how to skip unit test cases using maven mvn command when you are working with clean install or package a build.

Skipping tests is bad idea, but there might be situations where we need to skip tests in some environments (for example local) or we might need to build application without compiling and running tests, as tests are outdated. Let’s see how we can skip tests with Maven.

1. maven.test.skip=true

Define maven.test.skip system property and value should be true in pom.xml or from command line, Maven will skip the tests. In this tutorial, to run tests, we used install and package phases and configured Maven Surefire Plugin. Let’s see an example.

1.1. From Command line

Skip tests in install or package phase.

$ mvn clean install -Dmaven.test.skip=true     OR     $ mvn clean package -Dmaven.test.skip=true


3 Phases, 1. Copying test resources, 2. Compiling test sources and 3. Tests are skipped

1.2. From pom.xml configuration

If you would like to skip tests by default, you need to define maven.test.skip in pom.xml and set value true. This value can be changed to false using command line flag -Dmaven.test.skip=false to not to skip tests.

In pom.xml:


The above configuration skips all the tests by default when you build application using maven. To not skip tests, you need to set -Dmaven.test.skip value as false.

$ mvn clean install -Dmaven.test.skip=true

2. skipTests=true

In some cases, you may require compile test sources and only just need to skip tests. Similarly maven.test.skip, you can define system property skipTests from command line or in pom.xml.

From Command:

$ mvn clean install -DskipTests     OR     $ mvn clean package -DskipTests

Results: Only skips running tests, and Copying test resources, Compiling test sources phase will not be skipped.

In pom.xml:


To not skip tests, use command $ mvn clean package -DskipTests=false.

3. Maven surefire plugin

Alternatively skipTests property can define in surefire plugin. By default all tests will be skipped.



To not skip tests, you have to use following command.

$ mvn clean package -Dskip.tests=false

4. Skip Tests on specific environment

For example, you would need to skip tests on Local environment and should continue on other environments like Prod or QA, we can use Maven Profiles.


To run profile, following command can be used.

$ mvn clean package -Plocal

5. Conclusion

In this tutorial, we covered how to skip unit test cases using maven mvn command when you are working with clean install or package a build.

You also might interested in following Maven guides:

  1. Install Maven on Windows
  2. Install Maven on Mac
  3. Install Maven on Ubuntu
  4. Import maven project into Eclipse
  5. Maven run single test
  6. Maven set java version
  7. Maven run java main class

6. References

  1. Surefire Plugin
  2. skip tests


Please enter your comment!
Please enter your name here