Executing mvn clean install
on my parent pom builds all the sub-modules and runs the related junit tests. It doesn't run the integration tests.
After building and running the junits, I want to run a specific integration test in a particular sub-module.
I am using following command:
mvn clean install -DTest=integrationTestName
The job fails with No Test Found
error during build phase.
I also tried using
mvn clean install -DTest=integrationTestName -pl=sub-module-name
but this only builds my sub-module having integration test.
Question: How to run a single integration test of a certain module?
I suppose you tried the test
option (lower case) of the Maven Surefire Plugin to invoke a specific test, which Surefire couldn't find in the first module of the reactor build and hence fails.
I also suppose integration tests are executed by the Maven Failsafe Plugin. If not, they should, as mentioned by official documentation:
The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests. ... If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the
integration-test
phase and your integration test environment will not have been torn down correctly. .. The Failsafe Plugin will not fail the build during theintegration-test
phase, thus enabling thepost-integration-test
phase to execute.
To make it short: it's safer and much more robust to do so.
Although the plugin configuration entry for the Maven Failsafe Plugin is also test
, its corresponding command line option is it.test
, so you should instead run:
mvn clean install -Dit.test=SampleIT
Where SampleIT
is an integration Test (note the standard IT
suffix, recognized by default by Failsafe.
The official Running a Single Test documentation also provides further details on running single integration tests.
Also note: the invocation above will work if you don't have other integration tests in other modules of the build, otherwise it will fail not finding it earlier (before hitting the concerned module).
If you are using Surefire to run the concerned integration test (again, you shouldn't) or you have several modules running integration tests, you should then configure a profile in the concerned module which would take care of this specific invocation, something like as following:
<profiles>
<profile>
<id>run-single-it-test</id>
<activation>
<property>
<name>single.it.test</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<test>${single.it.test}</test>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
And then invoke the build as following:
mvn clean install -Dsingle.it.test=SampleIT
As such, Maven will activate the profile based on the existence of a value for the single.it.test
property and pass it to the test
property of the Failsafe Plugin (or the Surefire, if it was the case), Failsafe will ignore any other integration test for that execution and other modules would not suffer any impact (ignoring that property).
A_Di-Matteo's answer gets you most of the way there, but you need the following config for maven-surefire-plugin to suppress all the unit tests as well.
<profiles>
<profile>
<id>run-single-it-test</id>
<activation>
<property>
<name>single.it.test</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<failIfNoTests>false</failIfNoTests>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<test>${single.it.test}</test>
<failIfNoTests>false</failIfNoTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
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