How to skip Maven unit test

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. maven.test.skip=true

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>
mvn package

2. skipTests

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)

  1. maven.test.skip is a feature of Maven itself which skip compile tests, skip run test and just ignore any test processes.
  2. skipTests is a feature of surefire plugin which compiles the tests but don’t run the test case.
    Normally, I prefer skipTests
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s