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.

Related Posts

  • 28 March

    Generate source code jar for Maven based project

    Table of ContentsDeploy the jarCheck the local repository In this tutorial, we will see how to generate source code jar for maven based project. If you have simple java project, then you need to convert it maven project. Sometimes, you need to pack source code with your project jar. This is extremely useful when people […]

  • 21 March

    Install Maven on Mac

    Table of ContentsInstall maven manuallyDownload and extract MavenUpdate M2_HOME and PATHVerfiy maven installationInstall maven using Homebrew In this post, we will see how to install maven on Mac. If you are using the latest MacOSX, maven may be built-in and can be found at /usr/share/maven. Execute below command on terminal to see if you have […]

  • 21 March

    Run single test in maven

    Table of ContentsRun all testcaseRun all testcases from a test classRun specific test method from a test classRun multiple test methods from a test class In this post, we will see how to run single test in maven. If you want to execute all the Junit testcases in maven. You can run it below command. […]

  • 23 August

    log4j properties file example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 23 May

    log4j xml configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 20 February

    Log4j Maven configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.