I am relatively new to Maven. I have done a lot of research and digging on this topic, but I can't seem to find an answer, so I thought I would ask here.
Goal: I would like to run mvn clean install test
while skipping integration tests, as well as one particular unit test class.
I have tried the following:
mvn clean install -DskipITs -Dtest=!MyTestClass test
mvn clean install -DskipITs&&test=!MyTestClass test
mvn clean install -DskipITs&test=!MyTestClass test
However, none of the above commands seem to work. The first command of the three above made the most sense to me, but it seems as though the integration tests are being run when using that command. This is where my knowledge and understanding of Maven has a gap; I'm not sure if that's the expected behavior, or if that is the appropriate way to pass multiple properties on the command line?
When I run this command: mvn clean install -DskipITs test
, the integration tests are successfully skipped.
I am familiar with the Maven build life-cycle, but it is possible that I am misunderstanding something or missing a detail.
In Maven, you can define a system property -Dmaven. test. skip=true to skip the entire unit test. By default, when building project, Maven will run the entire unit tests automatically.
Skipping by default by initializing the skipTests element value to true in properties and then overriding it through the command line by mentioning the value of -DskipTests in the maven phase/build execution command.
The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.
By default, the integration tests will run but this setup allows you to easily disable them on the command-line as follows: mvn verify -Dskip.it=true.
Integration tests with maven are normally run with maven-failsafe-plugin
To tell this plugin to skip integration tests (make sure your integration test class names follow the convention *IT.java, otherwise you need to include them with <inclusions>
), you can do that in the plugin's configuration, or from the command line (official doc):
mvn test -DskipITs
Single tests can be skipped with:
mvn test -Dtest=!MyTestClass
So this should work:
mvn clean install -DskipITs -Dtest=!MyTestClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With