How to skip Maven unit test

By default, when building project, Maven will run the entire unit tests automatically. If any of unit test is failed, it will force Maven to abort the building process.

$ mvn install
$ mvn package

In real life, you may “STILL” need to build your project even some of the cases are failed.

Skip Unit Test

To skip the entire unit test, uses argument “-Dmaven.test.skip=true“.

$ mvn install -Dmaven.test.skip=true
$ mvn package -Dmaven.test.skip=true

Or define skipTests in maven-surefire-plugin.

pom.xml
   <plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>2.12.4</version>
	<configuration>
		<skipTests>true</skipTests>
	</configuration>
    </plugin>

Now, build the project again, the entire unit tests will be ignored.

Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • Sean

    Hi mkyong

    Your posts are really helpful! Thanks!

  • Sean

    Hi Mkyong

    Your posts are great! really helpful!

  • Aleksandar Bosancic

    Hello MK, I think it’s better solution for skip test use the properties

    3.0.5.RELEASE
    ……
    true

    Thanks,
    Aleksandar

    • Aleksandar Bosancic

      Sorry, ‘pre’ does not work so good :), here is config

      3.0.5.RELEASE
      …..
      true

  • Laurent C.

    I can argue about this commandline but this blog made it better:

    Source: Learning by Experience

    Recently came across this the existance of the -DskipTests argument while running maven.

    From the userguide:

    You can also skip the tests via command line by executing the following command:

    mvn install -DskipTests

    If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.

    mvn install -Dmaven.test.skip=true

    Skiptests is a feature of surefire, while -Dmaven.test.skip is a feature of maven itself.

  • http://alqaa.wordpress.com alka

    Waw! thx A lot master! your tip make my day more easy.

  • Scott

    Mykong,

    using true in the pom causes Maven to skip test execution. Is there any way to tell Maven to not compile the tests as well using a element in the pom instead of command line? Something such as true

    Thanks.

    • Scott

      Sorry, did not use the source code comment:

      true

  • Pete

    Well, the test was one we could safely ignore:
    testFindDomainBounds in the TimeSeriesCollectionTests returned:
    expected: but was:
    So we can assume it’s a basic rounding error, but very minor so safe to ignore.
    Not sure if it’s a Mac thing, perhaps a 64-bit issue but the test should be updated to round somewhat.

  • Pete

    Thanks alot mkyong. I had one unit test out of over 2000 fail in jFreeChart! Annoying, but your tip saved the day. Thanks again…
    Pete
    Melbourne, Australia

    • http://www.mkyong.com mkyong

      haha, you need to find out why the tests are failed, skip is just ignore it temporary :)

  • Pingback: How to skip Maven unit test | Just another software blog()

  • Pingback: Maven Tutorials | Tutorials()