maven工程使用jacoco-maven-plugin插件,无法生成覆盖率测试报告问题
·
maven工程使用jacoco-maven-plugin插件,无法生成覆盖率测试报告问题
当我们在maven工程中引入maven-surefire-plugin插件执行单元测试代码后,突然发现在集成jacoco-maven-plugin插件生成测试覆盖率报告时,因为插件参数配置问题,发现无法生成测试报告了。
解决方案
此时,
1、我们在jacoco-maven-plugin插件中定于一个属性<propertyName>surefireArgLine</propertyName>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
2、在 maven-surefire-plugin插件中使用这个参数即可生成测试报告<argLine>${surefireArgLine}</argLine>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<testFailureIgnore>true</testFailureIgnore>
<argLine>${surefireArgLine}</argLine>
</configuration>
</plugin>
3、maven-surefire-plugin,jacoco-maven-plugin显示无覆盖。
maven-surefire-plugin在多模块项目中指定两次时表现不可预测。
父模块的pom中引入了该插件,而子模块pom也在构建部分中有它。因此,它似乎正在运行测试,但子模块中的覆盖率始终为0。
修复是从子模块pom中删除maven-surefire-plugin,并且只在父pom的build部分中有它。
问题得到了解决。
上述问题只是解决方案之一,具体问题具体分析。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)