我拥有与JaCoCo报告相同覆盖范围的所有工具:69%的线覆盖率和23%的分支覆盖率.
注意:屏幕截图已经过了几天,所以它们的值略有不同,但差异是< 1%
jenkins:
然而,Sonar报告了不同的值:
Maven项目的结构如下:
>主要(聚合器)
> java模块
> js(节点)模块
您可以在main和java模块上看到相同的覆盖范围,并且没有js one的覆盖范围.
我正在使用最新版本的jacoco,jacoco-maven-plugin和Sonar的Java插件.
以下是来自mvn声纳的相关构建日志片段:声纳 – 似乎都是有序的:
$egrep -i 'jacoco|\[warn]' consoleText
[WARN] [04:34:29.569] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[WARN] [04:34:29.576] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[WARN] [04:34:29.593] 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[INFO] [04:34:32.704] JaCoCoItSensor: JaCoCo IT report not found: /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/jacoco-it.exec
[WARN] [04:34:32.952] Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property
[WARN] [04:34:50.101] Cobertura report not found at /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/site/cobertura/coverage.xml
[INFO] [04:35:03.391] Sensor JaCoCoSensor
[INFO] [04:35:03.406] Analysing /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/jacoco.exec
[INFO] [04:35:03.712] Sensor JaCoCoSensor (done) | time=321ms
[INFO] [04:35:03.712] Sensor JaCoCoOverallSensor
[INFO] [04:35:03.714] Analysing /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/jacoco.exec
[INFO] [04:35:03.762] Analysing /home/acme/workspace/example-Sonar-DSL/modules/example-main/target/sonar/jacoco-overall.exec
[INFO] [04:35:03.906] Sensor JaCoCoOverallSensor (done) | time=194ms
[INFO] [04:35:11.013] JaCoCoSensor: JaCoCo report not found : /home/acme/workspace/example-Sonar-DSL/modules/frontend/target/jacoco.exec
[INFO] [04:35:11.013] JaCoCoItSensor: JaCoCo IT report not found: /home/acme/workspace/example-Sonar-DSL/modules/frontend/target/jacoco-it.exec
[INFO] [04:35:11.179] JaCoCoSensor: JaCoCo report not found : /home/acme/workspace/example-Sonar-DSL/target/jacoco.exec
[INFO] [04:35:11.179] JaCoCoItSensor: JaCoCo IT report not found: /home/acme/workspace/example-Sonar-DSL/target/jacoco-it.exec
这是Sonar的Java插件中的错误吗?
我认为,当不同人配置的3个其他工具始终显示不同的值时,声纳报告的度量标准极不可能正确.
解决方法:
以下是计算“单元测试覆盖率”度量的方法:
> NUMBER_OF_LINES =行数条件数.
> COVERED_LINES = NUMBER_OF_LINES – (未覆盖的行数)未覆盖的条件数.
COVERAGE =(100 * COVERED_LINES)/ NUMBER_OF_LINES.