My Java Maven project separates unit tests from integration tests in the directory structure:
src/test/java
; src/integration-test/java
. src/integration-test/java
is a non-default test source directory, so I added it manually to the project using build-helper-maven-plugin
, as you can see:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
...
</executions>
</plugin>
I also used maven-failsafe-plugin
to include the test integration classes in the test execution flow, as shown below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
This approach works, but obliges me to use a naming convention in the test classes. Precisely, only the ones ending with "IntegrationTest" will be executed.
I would like to configure the plugin based on a naming convention in the path and not in the file name. Precisely, I intend to allow all classes under src/integration-test/java
regardless the file names. I did not succeed so far and every tutorial in the web only shows the approach I implemented and showed you above.
Does anyone have any suggestion on how to do that?
Thanks
AFAIK, both plugins (surefire and failsafe) simply use the classpath. So, to achieve what you want, you either have to use a naming convention (eg Test vs IT as is standard) or use two different modules.
The only other (really ugly) solution I could find would be:
This might work, but is hell to maintain and code ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.