In Maven, to skip running unit tests, uses this -Dmaven.test.skip=true

By default, when building project, Maven will run the entire unit tests automatically. If any unit tests is 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.

1. maven.test.skip=true

1.1 To skip unit tests, uses this argument -Dmaven.test.skip=true

Terminal

$ mvn package -Dmaven.test.skip=true

1.2 Or defined in pom.xml and run the package command normally.

pom.xml

    <properties>
        <maven.test.skip>true</maven.test.skip>
    </properties>

$ mvn package
#no test

2. skipTests

2.1 Alternatively, use this surefire -DskipTests

Terminal

$ mvn package -DskipTests

2.2 Or this.

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>	

3. maven.test.skip vs skipTests

The core difference :

  1. maven.test.skip is a feature of Maven itself, skip compile tests, skip run test, just ignore any test processes.
  2. skipTests is a feature of surefire plugin, compile the tests but skip running it.

Normally, I prefer maven.test.skip

References

  1. Skipping Tests