Prevent unit tests but allow integration tests in Maven

Viewed 71424

I've a Maven build in which I use the SureFire plugin to run some unit tests, and the FailSafe plugin to run some integration tests. I would like a way to run just the FailSafe plugin's tests.

It's not a good solution for me to add different profiles or anything in the pom, because it's a multimodule build and I don't want to have to edit every module's pom.

There are skip.tests and maven.test.skip and skipTests which stop all tests, and skipITs, which stops only the failsafe plugin.

So, is there a command-line flag for Maven like skipITs, but instead with the functionality of "onlyITs"?

7 Answers

Hope this helps!

Try to run test only with FailSafe (plugin for integration-test - it will allow you to run only integration tests with this kind naming, by default: */IT.java, **/IT.java, */*ITCase.java; , but you can easily change that from pom file)

mvn failsafe:integration-test

And when you want to use only SureFire (plugin for unit-testing)

mvn surefire:test

or one test at a time with:

mvn -Dtest=MyUnitlTest

This skips the UnitTests triggered by SureFire and tests only one test:

mvn failsafe:integration-test -Dit.test=YourTestName

You can also provide a pattern: mvn failsafe:integration-test -Dit.test=*

(Maven 3.6.3)

Related