By default in Maven, when building a project, Maven will run the entire unit tests automatically. If any unit tests are failed, it will force Maven to abort the building process. In real life, you may still need to build your project even some of the cases are failed.
We have two ways for skipping unit test either maven.test.skip=true or skipTests
1.1 To skip unit tests, uses this argument -Dmaven.test.skip=true
mvn package -Dmaven.test.skip=true
1.2 Or defined in pom.xml and run the package command normally.
<properties> <maven.test.skip>true</maven.test.skip> </properties>
2.1 Alternatively, use this surefire -DskipTests
mvn package -DskipTests
2.2 Or add this in pom.xml and run the package command normally.
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
comparision (maven.test.skip vs skipTests)
- maven.test.skip is a feature of Maven itself which skip compile tests, skip run test and just ignore any test processes.
- skipTests is a feature of surefire plugin which compiles the tests but don’t run the test case.
Normally, I prefer skipTests