I have a multi-module java spring boot project. Here is my project structure
- pom.xml (root)
- war (project)
--- pom.xml
--- src/.../SBMainApplication.java
- api (project)
--- pom.xml
--- src/../Controller1.java
--- test/unit/
--- test/integration
- service (project)
--- pom.xml
--- src/../Service1.java
--- test/unit/
- domain(project)
--- pom.xml
--- src/../Repository1.java
--- test/unit/
As you can see, there are 4 modules and finally when war module is built it pakages other modules as a Spring Boot jar.
I have enabled jacoco for code coverage and it works fine for all unit tests, which are there in each module. The integration tests however only exist in api module. My expectation is if I am running a SpringRunner integration on API and the flow is Controller1 -> Serivice1 -> Repository1 -> h2 database, the integration tests would cover all the classes in other modules too. But in the jacoco coverage only the controllers are being covered but the services and repositories are not covered. Here is my jacoco configuration in the root pom
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<excludes>
<exclude>com/../model/**/*</exclude>
<exclude>com/../common/model/**/*</exclude>
<exclude>com/../repository/entity/**/*</exclude>
<exclude>**/*Constants.java</exclude>
<exclude>**/*Configuration.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-initialize-ut</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-initialize-it</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<excludes>
<exclude>com/../model/**/*</exclude>
<exclude>com/../common/model/**/*</exclude>
<exclude>com/../repository/entity/**/*</exclude>
<exclude>**/*Constants.java</exclude>
<exclude>**/*Configuration.java</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>jacoco-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<excludes>
<exclude>**/*IntTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*IntTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Is there a way where service and repositories are covered in jacoco by running the integration tests in another module?