Skip tests in maven

In this tutorial, we will see how to skip tests in maven.

It is not a good idea to skip junit tests while building project in maven but sometimes, you may need to skip it for building new code and want to test it quickly.

For example: In a large project, where you have more than 1000 junit test cases and you want to change small piece of code and run it quickly to test it. You may want to skip running test cases to save time and should consider this as an intermediate build.

Using maven.test.skip=true

You can use -Dmaven.test.skip=true to skip test cases. It will not compile and execute the test cases.

Here is an example:
Go to the project location on terminal and execute below command.

mvn install -Dmaven.test.skip=true

You can do the same in pom.xml with the following properties.

Here is an example of complete pom.xml.

Execute below command to skip test via properties taf.

mvn install

You can use this property in maven profile as well.

Execute below command to skip test via profile.

mvn install -PskipTestMavenProfile

Using SkipTests

You can use -DskipTest also to skip tests. This will still compile the testcases but will not execute them.

mvn install -DskipTest

In pom.xml, you can use it with Maven Surefire Plugin.

Skip tests in Maven in eclipse

You can use above options to skip tests in eclipse. Eclipse also provide checkbox to skip test cases in eclipse.

Here is the screenshot for the same.

Skip tests eclipse

Conclusion

You can use -Dmaven.test.skip=true or -DskipTests to skip tests in maven. Please note that
-Dmaven.test.skip=true will neither compile the testcases nor execute them while -DskipTests will compile the testcases but will not execute them.

That’s all about how to skip tests in maven.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *