My directory structure is like so:
src/integrationTest/java
src/test/java
src/main/java
I am trying to get failsafe to pick-up the integration tests, but failing to do so in the way I would like.
I have tried this:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<testSourceDirectory>src/integrationTest/java</testSourceDirectory>
<testClassesDirectory>${project.build.directory}/it-classes</testClassesDirectory>
</configuration>
</plugin>
and this:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>src/integrationTest/**/*.java</include>
</includes>
</configuration>
</plugin>
to no avail; failsafe does not find tests to run.
I have been able to use the build-helper-maven plugin to add a test-source directory and then failsafe runs the tests.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-integration-test-source-as-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integrationTest/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
However, the problem now is that surefire now also runs the tests as unit-tests. Also it seems unnecessary to use another plugin when failsafe should be able to find the tests; I would prefer to not to need to use build-helper maven plugin and configure surefire to exclude that path.
What am I doing wrong?
By default failsafe is configured to only include IT*.java, *IT.java or *ITCase.java. While at the same time, only test sources from src/test/java
are compiled. You need to modify both of these behaviors.
Use build-helper-maven-plugin
to add src/integationTest/java
as test source for maven-compiler-plugin
to pick up automatically. (You've already done this in your last attempt.)
Direct maven-surefire-plugin
to exclude your integration tests (see example below) or to include only non-integration tests (see default includes).
Direct maven-failsafe-plugin
to only include your integration tests instead of default includes.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<excludes>
<exclude>**/*Stuff.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*Stuff.java</include>
</includes>
</configuration>
</plugin>
In fact using testClassesDirectory
might also work for limiting scope of each test plugin, but you would have to make changes to maven-compiler-plugin
to output classes to different folders, perhaps splitting it's test-compile
execution into two, so maybe it's not worth the effort.
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