• <bdo id='0GBWY'></bdo><ul id='0GBWY'></ul>
  • <tfoot id='0GBWY'></tfoot>
      1. <legend id='0GBWY'><style id='0GBWY'><dir id='0GBWY'><q id='0GBWY'></q></dir></style></legend>

        <small id='0GBWY'></small><noframes id='0GBWY'>

        <i id='0GBWY'><tr id='0GBWY'><dt id='0GBWY'><q id='0GBWY'><span id='0GBWY'><b id='0GBWY'><form id='0GBWY'><ins id='0GBWY'></ins><ul id='0GBWY'></ul><sub id='0GBWY'></sub></form><legend id='0GBWY'></legend><bdo id='0GBWY'><pre id='0GBWY'><center id='0GBWY'></center></pre></bdo></b><th id='0GBWY'></th></span></q></dt></tr></i><div id='0GBWY'><tfoot id='0GBWY'></tfoot><dl id='0GBWY'><fieldset id='0GBWY'></fieldset></dl></div>
      2. jacoco 分支覆盖和声纳条件覆盖有什么区别?

        时间:2024-05-09

          <small id='6d8pl'></small><noframes id='6d8pl'>

            <tbody id='6d8pl'></tbody>
          1. <i id='6d8pl'><tr id='6d8pl'><dt id='6d8pl'><q id='6d8pl'><span id='6d8pl'><b id='6d8pl'><form id='6d8pl'><ins id='6d8pl'></ins><ul id='6d8pl'></ul><sub id='6d8pl'></sub></form><legend id='6d8pl'></legend><bdo id='6d8pl'><pre id='6d8pl'><center id='6d8pl'></center></pre></bdo></b><th id='6d8pl'></th></span></q></dt></tr></i><div id='6d8pl'><tfoot id='6d8pl'></tfoot><dl id='6d8pl'><fieldset id='6d8pl'></fieldset></dl></div>
              • <tfoot id='6d8pl'></tfoot>

                • <bdo id='6d8pl'></bdo><ul id='6d8pl'></ul>

                  <legend id='6d8pl'><style id='6d8pl'><dir id='6d8pl'><q id='6d8pl'></q></dir></style></legend>
                • 本文介绍了jacoco 分支覆盖和声纳条件覆盖有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 SonarQube 扫描仪(版本 3.1.0.1141)分析 java 代码.

                  I'm trying to analyze java code with the SonarQube Scanner (version 3.1.0.1141).

                  • SonarQube 版本:5.6.6
                  • Sonar Java 插件版本:4.12.0.11033
                  • jacoco 版本:0.8.0

                  我已经用这些属性填充了 sonar-project.properties:

                  I have filled the sonar-project.properties with those properties :

                  # Sonar sources and metadata
                  sonar.language=java
                  sonar.sources=src/main
                  sonar.java.source=1.8
                  sonar.sourceEncoding=UTF-8
                  sonar.java.binaries=target/classes
                  sonar.java.libraries=target/lib
                  
                  sonar.tests=src/test
                  sonar.java.coveragePlugin=jacoco
                  sonar.junit.reportsPath=target/surefire-reports
                  sonar.surefire.reportsPath=target/surefire-reports
                  

                  虽然 jacoco 报告给了我一个班级的这个结果:

                  While jacoco report gives me this result for one class :

                  • 覆盖率:84%
                  • 分支机构覆盖率:71%
                  • 错过:9
                  • 复杂度:24
                  • 错过:6
                  • 行数:69
                  • 错过:0
                  • 方法:8
                  • 错过:0
                  • 类:1

                  SonarQube 显示度量:

                  SonarQube displays the measures :

                  • 条件覆盖率62.5%
                  • 覆盖率81.7%
                  • 线路覆盖率92.8%
                  • 覆盖69
                  • 的行
                  • 整体状况覆盖率62.5%
                  • 整体覆盖率81.7%
                  • 整体线路覆盖率92.8%
                  • 未发现的分支总数15
                  • 未覆盖的总线 5
                  • 未覆盖的分支15
                  • 未覆盖的线 5

                  根据声纳指标定义页面,条件覆盖的声纳键是分支覆盖率,所以我认为条件和分支覆盖率是一回事.

                  According to the sonar metric definition page, the sonar key for condition coverage is branch_coverage, so I thought condition and branch coverage are the same things.

                  如何解释不同的结果?

                  推荐答案

                  假设你有一些构造

                  if(a == 1 && b == 2) {
                    //do this
                  } else {
                    //do that
                  }
                  

                  你有两个分支

                  • 这样做
                  • 这样做

                  还有两个条件

                  • a == 1 (cond1)
                  • b == 2 (cond2)

                  如果你有两个测试用例

                  • 测试(a == 1,b == 2)
                  • 测试(a == 2,b == 2)

                  你覆盖了两个分支,因为 (cond1 && cond2) 的组合条件要么为假要么为真,

                  You're covering both branches because the combined condition of (cond1 && cond2) is either false or true,

                  但是你只完全覆盖了 cond1 并且只覆盖了 cond2 的一半,即 75% 的条件覆盖率.

                  But you only cover cond1 fully and only half of cond2, thats 75% condition coverage.

                  要获得完整的条件覆盖,您需要额外的测试

                  To get full condition coverage, you need an additional test

                  • 测试(a == 1,b == 1)

                  这两个工具都使用每行的分支信息来计算覆盖率.我对我的一些代码进行了测试,覆盖条件"(Sonarqube)的数量与 Jacoco 报告中的总分支"数量相匹配 - 但我使用了 jacoco 和 Sonarqube/sonar-java 的最新版本.所以除了名称之外,措施是/应该是相同的.

                  Both tools calculate the coverage using the branch information per line. I run a test on some of my code, and the number of "conditions to cover" (Sonarqube) matches the number of total "Branches" in Jacoco report - but I used the most recent versions for jacoco and Sonarqube/sonar-java. So apart from the name, but measures are/should be the same.

                  但鉴于您提供的数字,您的分析总体上似乎有些奇怪.不仅百分比值不同,而且绝对值也不同(Jacoco 中的 9 个未发现分支与 Sonarqube 中的 15 个未发现分支).

                  But given the numbers you provide, there seems something odd with your analysis in general. It's not only the percentage-values that differ, but the absolute ones as well (9 uncovered branches in Jacoco vs 15 uncovered Branches in Sonarqube).

                  所以我检查了您正在使用的版本 - jacoco 0.8.0 和使用 jacoco 0.7.9 的 sonar-java 插件 v4.11.0.11033.

                  So I checked the versions you're using - jacoco 0.8.0 and the sonar-java plugin v4.11.0.11033 which uses jacoco 0.7.9.

                  Jacoco 0.8.0 的发行说明阅读

                  在创建报告期间,各种编译器生成的工件被过滤掉,否则需要不必要的,有时甚至是不可能的技巧来避免部分或遗漏的覆盖:

                  During creation of reports various compiler generated artifacts are filtered out, which otherwise require unnecessary and sometimes impossible tricks to not have partial or missed coverage:

                  • 方法 valueOf 和枚举类型的值 (GitHub #491).
                  • 私有的空无参数构造函数 (GitHub #529).
                  • 使用 @lombok.Generated 注释的方法可以更好地与 Lombok >= 1.16.14 集成.Rüdiger zu Dohna (@t1) (GitHub #513) 的初步分析和贡献.
                  • 使用 @groovy.transform.Generated 注释的方法可以更好地与 Groovy >= 2.5.0 集成.感谢 Andres Almiray (@aalmiray) 将注释添加到 Groovy (GitHub #610).
                  • 同步块的部分字节码 (GitHub #501).
                  • try-with-resources 语句的部分字节码 (GitHub #500).
                  • finally 块的部分字节码 (GitHub #604).
                  • java.lang.String 值上 switch 语句的部分字节码 (GitHub > #596).

                  所以我最好的猜测是,Jacoco 0.8.0 生成的报告过滤掉了一些提到的生成的工件,有效地减少了分支的总数.然而,Sonar-Java 使用 Jacoco 0.7.9,它不会过滤掉生成的工件,因此数量更高(覆盖率更低).

                  So my best guess here would be, that the report generated by Jacoco 0.8.0 filtered out some of the mentioned generated artifacts effectively reducing to total number of branches. Sonar-Java however uses Jacoco 0.7.9 which does not filter out generated artifacts and therefore the numbers are higher (and the coverage lower).

                  也许您应该将您的 jacoco 版本降级到 0.7.9 或升级 sonar-java 插件.

                  Maybe you should either downgrade your jacoco version to 0.7.9 or upgrade the sonar-java plugin.

                  这篇关于jacoco 分支覆盖和声纳条件覆盖有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如果 JUnit 覆盖率低于某个阈值,如何使 Maven 构建失败 下一篇:使用特定 jdk 启动 SonarQube 服务器

                  相关文章

                    <small id='OXHNo'></small><noframes id='OXHNo'>

                    • <bdo id='OXHNo'></bdo><ul id='OXHNo'></ul>
                    <legend id='OXHNo'><style id='OXHNo'><dir id='OXHNo'><q id='OXHNo'></q></dir></style></legend>
                    <tfoot id='OXHNo'></tfoot>
                    1. <i id='OXHNo'><tr id='OXHNo'><dt id='OXHNo'><q id='OXHNo'><span id='OXHNo'><b id='OXHNo'><form id='OXHNo'><ins id='OXHNo'></ins><ul id='OXHNo'></ul><sub id='OXHNo'></sub></form><legend id='OXHNo'></legend><bdo id='OXHNo'><pre id='OXHNo'><center id='OXHNo'></center></pre></bdo></b><th id='OXHNo'></th></span></q></dt></tr></i><div id='OXHNo'><tfoot id='OXHNo'></tfoot><dl id='OXHNo'><fieldset id='OXHNo'></fieldset></dl></div>