简体   繁体   English

Jacoco - 如何检查哪些行缺少覆盖

[英]Jacoco - How to check which lines are missing coverage

I am using jacoco for Test coverage verification in a Java Library created with Gradle.我在使用 Gradle 创建的 Java 库中使用 jacoco 进行测试覆盖率验证。 I have set the verification rule to limit minimum coverage to 1.0 (100%).我已将验证规则设置为将最小覆盖率限制为 1.0 (100%)。 I have a few classes in my code which are not meeting the criteria.我的代码中有一些不符合标准的类。 based on the unit-tests that I have written, I don't think I am missing any line of code.根据我编写的单元测试,我认为我没有遗漏任何代码行。

on those lines, I was wondering if there is a was to make jacoco print out which lines are not getting covered by unit tests during the build process?在这些行上,我想知道是否有让 jacoco 在构建过程中打印出哪些行没有被单元测试覆盖?

currently jacoco causes a build failure reporting the coverage ration for each files that didn't meet the bar but it does not provide any information on specific lines that were not covered.目前 jacoco 导致构建失败,报告每个不符合标准的文件的覆盖率,但它没有提供有关未覆盖的特定行的任何信息。

I was able to configure My Gradle-Groovy project to start generating Jacoco coverage reports by doing the following:通过执行以下操作,我能够配置 My Gradle-Groovy 项目以开始生成 Jacoco 覆盖率报告:

added jacoco plugin to buildscript in build.gradlebuild.gradle jacoco插件添加到buildscript

apply plugin: 'jacoco'

adding a custom configuration:添加自定义配置:

jacocoTestReport {
 dependsOn test
}

chaining jacocoTestReport to your test taskjacocoTestReport链接到您的test任务

test {
  finalizedBy jacocoTestReport 
}

This ensures, report is always generated after tests run.这可确保在测试运行后始终生成报告。

Note: if you have added both jacoco and java plugin, reports are automatically generated and stored at $buildDir/reports/jacoco/test in such a scenario, you can skip above steps.注意:如果您同时添加了 jacoco 和 java 插件,在这种情况下会自动生成报告并存储在$buildDir/reports/jacoco/test中,您可以跳过上述步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM