Apache Maven: Skipping unit test using surefire plugin

In this article, we will learn and understand how to skip unit test while building maven based project using surefire plugin

One of the maven’s features is to run unit test automatically and if some of the test cases fail, then maven build fails

Irrespective of the unit test failure, we still need to move on to build the project successfully. In these circumstances, we have to suppress maven from running unit test for us which results in “BUILD FAILURE”

Skip unit test using surefire plugin

If we need to suppress/disable running unit test for a particular project, configure “skipTests” tag to true of surefire plugin in pom.xml




Skipping unit test from command line

You can skip unit test running below maven command

mvn install -DskipTests


mvn install -Dmaven.test.skip=true


To be noted

With above pom.xml configuration, by-default maven suppresses or disable running unit test

But to re-enable them, use below maven command from CLI

mvn install -DskipTests=false




Read Also:


Happy Coding !!
Happy Learning !!

Apache Maven: Exclusions and Inclusions of unit test
Apache Maven: Plugins explanation