Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Skip All Integration Tests (-DskipITs) and One Unit Test mvn Command Line

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.

like image 943
Daniel Avatar asked Feb 15 '19 17:02

Daniel


People also ask

How do you skip a unit test?

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.

How can you override skipTests parameter in command line?

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.

How do I run a specific integration test in Maven?

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.

How do I skip a test in spring boot?

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.


1 Answers

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
like image 171
hovanessyan Avatar answered Nov 07 '22 15:11

hovanessyan