How to skip Maven unit tests
skip maven unit test
maven.test.skip
skipTests
This article will present how to skip Maven unit tests.
By default, when building a project, Maven will run the entire unit tests automatically and the problem is that if any unit tests fail, it will force Maven to abort the building process. Usually, during the development process, you may still need to build your project even if some of the cases are failed.
Here are two methods how to skip Maven tests:
Option 1
Using maven.test.skip=true
, Maven build-in feature.
From command line
# mvn package -Dmaven.test.skip=true
Defined in the pom.xml
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
and then you run the maven command normally:
#mvn package
Option 2
Using surefire plugin property skipTests
.
From command line
# mvn package -DskipTests
Defined in the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
and then you run the maven command normally:
#mvn package
The difference is that maven.test.skip will skip everything on tests (compile and run) and skipTests will compile the tests and will skip only the running part.