最外层POM配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<forkMode>once</forkMode>
<reuseForks>true</reuseForks>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>@{argLine}</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*Test*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>my-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>my-report</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
本地统计代码单元测试覆盖率
mvn test jacoco:prepare-agent jacoco:report jacoco:report-aggregate
远端SonarQube执行
jenkis服务器需要配置Jacoco
mvn test jacoco:prepare-agent jacoco:report jacoco:report-aggregate sonar:sonar -Dsonar.projectKey=xxxxx -Dsonar.projectName=xxx
注意事项
Q1 target目录下未编译test目录下的代码
常见报错:
Not compiling test sources
Skipping JaCoCo execution due to missing execution data file.文章来源:https://www.toymoban.com/news/detail-698933.html
修改插件配置文章来源地址https://www.toymoban.com/news/detail-698933.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<!--.....-->
<skip>false</skip><!--注意此处-->
<!--.....-->
</configuration>
</plugin>
到了这里,关于Springboot 多模块项目集成Jacoco统计单元测试覆盖率的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!