【问题标题】:maven scoverage check for lines/branches not covered by unit testsmaven 覆盖检查单元测试未涵盖的行/分支
【发布时间】:2021-05-10 11:06:57
【问题描述】:
我对 maven scoverage 插件很陌生,它是我正在使用的团队中首选的代码覆盖工具。
我正在尝试使用以下命令生成测试覆盖率报告:
mvn scoverage:report
它给了我一份详细的报告,显示了代码行和分支方面的类名和代码覆盖率,但它没有显示单元测试未涵盖哪些代码行/分支。
是否有可用于显示这些行或作为报告的一部分生成的覆盖范围选项?
我尝试过谷歌搜索,但找不到任何有助于了解的内容
【问题讨论】:
标签:
maven
unit-testing
maven-plugin
【解决方案1】:
所以最后我想通了,我需要做的就是在插件部分进行一个小改动以覆盖我的 pom 文件并将突出显示设置为 true
之前:
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<configuration>
<minimumCoverage>80</minimumCoverage>
<failOnMinimumCoverage>true</failOnMinimumCoverage>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal> <!-- or integration-check -->
</goals>
<phase>prepare-package</phase> <!-- or any other phase -->
</execution>
</executions>
</plugin>
之后:
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<configuration>
<highlighting>true</highlighting>
<minimumCoverage>80</minimumCoverage>
<failOnMinimumCoverage>true</failOnMinimumCoverage>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal> <!-- or integration-check -->
</goals>
<phase>prepare-package</phase> <!-- or any other phase -->
</execution>
</executions>
</plugin>