我有一个多模块java spring boot项目。这是我的项目结构
- 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/
您可以看到,有4个模块,最后在构建 war 模块时,它将其他模块包装为Spring Boot jar。
我已经启用了jacoco的代码覆盖范围,并且对所有模块中的所有单元测试都可以正常工作。但是,集成测试仅存在于 api 模块中。我的期望是,如果我在API上运行SpringRunner集成,并且流程为Controller1-> Serivice1-> Repository1-> h2数据库,那么集成测试也将涵盖其他模块中的所有类。但是在jacoco涵盖范围中,仅涵盖了控制器,而未涵盖服务和存储库。这是我在根pom中的jacoco配置
<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>
有没有一种方法可以通过在另一个模块中运行集成测试来在jacoco中覆盖服务和存储库?