I have a Spring Boot multi-module project that meets all of the requirements except Integration testing. The unit tests, defined in src/test work fine in surefire as part of the test phase.
Multiple hours of experimenting with failsafe have not brought about the desired results. failsafe is not able to find any of the tests. I am assuming this is based on:
- The test classes not being part of the .jar file associated with each of the modules.
- No way I've been able to figure out how to get the test .jar file on the class path where failsafe will look for tests.
My project:
project folder
--pom.xml
|
----application
------pom.xml
------src
--------main
--------test
|
----model
------pom.xml
|
------data
--------pom.xml
--------src
----------main
----------test
|
------repository
--------pom.xml
--------src
----------main
----------test
My parent pom:
<project>
....
<artifactId>master</artifactId>
....
<modules>
<module>model</module>
<module>application</module>
</modules>
....
<dependencyManagement>
<dependencies>
<!-- Model -->
<dependency>
<groupId>xxx.xxx.xxx</groupId>
<artifactId>data</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>xxx.xxx.xxx</groupId>
<artifactId>repository</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Application -->
<dependency>
<groupId>xxx.xxx.xxx</groupId>
<artifactId>application</artifactId>
<version>${project.version}</version>
</dependency>
</dependencyManagement>
....
<build>
<!-- defined here and then used on a module-by-module basis -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Configure failsafe -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/Abstract*.java</exclude>
</excludes>
<additionalClasspathElements>
<additionalClasspathElement>
${project.basedir}/../../model/data/target/data-${project.version}-tests.jar
</additionalClasspathElement>
</additionalClasspathElements>
<dependenciesToScan>
<dependency>
com.optum.cirrus:repository
</dependency>
</dependenciesToScan>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</pluginManagement>
....
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Note that I create a test-jar for all of the modules along with a jar based on the main code. This works as intended with just the src/test code in the test-jar file.
The module pom files are:
<project>
<parent>
<artifactId>master</artifactId>
</parent>
....
<artifactId>model</artifactId>
<packaging>pom</packaging>
<modules>
<module>data</module>
<module>repository</module>
</modules>
....
</project>
<project>
....
<parent>
<artifactId>model</artifactId>
</parent>
<artifactId>data</artifactId>
<packaging>jar</packaging>
<name>data</name>
....
</project>
<project>
....
<parent>
<artifactId>model</artifactId>
</parent>
<artifactId>repository</artifactId>
<packaging>jar</packaging>
<name>repository</name>
<dependencies>
<dependency>
<groupId>xxx.xxx.xxxx</groupId>
<artifactId>data</artifactId>
</dependency>
</dependencies>
....
</project>
<project>
....
<parent>
<artifactId>model</artifactId>
</parent>
<artifactId>master</artifactId>
<packaging>jar</packaging>
<name>application</name>
<dependencies>
<dependency>
<groupId>xxx.xxx.xxxx</groupId>
<artifactId>resources</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
failsafe only runs as part of the application build. This is after the spring boot repackaging has been processed, though both the original and the repackaged jar files are available.
When I run maven with debug on I see the repackaged application jar plus the resources jar [I am assuming this is there based on the dependency element defined on failsafe] plus the resources-test.jar [assumed to be there based on the additionalClasspathElements element] are on the class path.
I am at a loss on how to configure failsafe such that it can find the test classes that are included in the test.jar file the same way the unit tests are found when only surefire and the single module are involved.
One unexplored possibility might be to create a second artifact from, for example, the resources pom.xml, that would create the test.jar I could then pass that to failsafe as the dependency. Note that 'just create a separate module that only has src/test in it that is dependent on the src/main code' might achieve that result but the solution seems like a real kludge ... munging what appears to be a standard source code file structure to fit a maven model.
Life can not be that bizarre and what is being done can not be such a 'one-off' that the desired results have not already been achieved. This means I am obviously doing something wrong, but have no clue as to what. Any suggestions would be appreciated.
Thanks.