Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run individual test in the integration-test target in maven

We have a hundreds of tests defined for our integration-test phase lifecycle in maven, and they take a long time to finish.

What I want to do is run just one test in the integration-test. I tried doing :

mvn -Dtest=<my-test> integration-test 

but that does not work. The -Dtest runs only the tests in the unit test goal, not the integration-test phase. I tried the -Dintegration-test=<my-test> instead, and that was ignored.

Is there a way to do that ?


My configuration is:

<plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-surefire-plugin</artifactId>      <executions>          <execution>              <id>surefire-it</id>              <phase>integration-test</phase>              <goals>                  <goal>test</goal>              </goals>              <configuration>                  <excludes>                      <exclude>none</exclude>                  </excludes>                  <includes>                     <include>**/api/**</include>                  </includes>      .....  
like image 647
Jalpesh Avatar asked May 21 '09 19:05

Jalpesh


People also ask

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.

Does mvn test run integration tests?

The Maven build lifecycle now includes the "integration-test" phase for running integration tests, which are run separately from the unit tests run during the "test" phase. It runs after "package", so if you run "mvn verify", "mvn install", or "mvn deploy", integration tests will be run along the way.


2 Answers

If you're using the Maven failsafe plugin, you can run a single integration test by setting the it.test property to your fully qualified test class name:

mvn -D it.test=your.TestCase verify 

See the failsafe plugin docs for more info.

like image 85
A Lee Avatar answered Sep 21 '22 16:09

A Lee


The Failsafe documentation would have you specify the test like so:

mvn -Dit.test=BrokenIT verify 

However, -Dit.test does not appear to work any longer. Rather, the same parameter used to specify a Surefire test will apparently work for Failsafe as well. For example:

mvn -Dtest=WorksIT verify 

I've filed a bug (EDIT: which was closed as "Cannot Reproduce" in 2.12) to correct the documentation.

like image 24
Lyle Avatar answered Sep 18 '22 16:09

Lyle