Maven plus Spring Boot plus Multi Module failover integrated testing

I have a Spring Boot multi-module project that meets all the requirements except integration testing. The unit tests defined in the src / test command are fully operational as part of the test phase.

Several hours of experimenting with fail-safe did not produce the desired results. fail-safe cannot find any of the tests. I assume this is based on:

  • Test classes that are not part of the .jar file associated with each of the modules.
  • In no way I was able to figure out how to get the test .jar file on the classpath where the failover 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>

      

Please note that I am creating a test jar for all modules along with the jar based on the main code. This works as intended with just the src / test code in the test jar file.

Pom module files:

<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> 

      

fault tolerance is performed only as part of the application build. This happens after Spring repackaging has been processed, although both original and repackaged jars are available.

When I run maven with debug, I see the repackaged jar app plus the jar resource [I assume this exists based on the dependency item defined in the failover], plus the test.jar resource [assumes it is based on the accessClasspathElements element] are found on the way to class.

I am having a hard time setting up failover so that it can find the test classes that are included in the test.jar file, the same as unit tests when only surefire and one module are involved.

One unexplored possibility might be to create a second artifact, for example from pom.xml resources, which will create test.jar. Then I could pass this for security as a dependency. Note that "just creating a separate module that only has src / test in it, depending on src / main code" can achieve this result, but the solution looks like a real kludge ... munging, which seems like standard file structure source code to fit the maven model.

Life cannot be so strange, and what is being done cannot be so "one-off" that the desired results have not yet been achieved. This means that I am obviously doing something wrong, but have no idea what. Any suggestions would be appreciated.

Thank.

+3


source to share





All Articles