Sonar reports different line and branch coverage than Idea, Eclipse, Maven and Jenkins

拜拜、爱过 提交于 2020-01-03 17:16:33

问题


I have all those tools reporting the same coverage with JaCoCo: 69% line coverage and 23% branch coverage.

Note: Screenshots had been taken over several days so they have slightly different values, but the variance is < 1%

Jenkins:

Maven:

Eclipse:

However Sonar reports different values:

Maven project is structured as follows:

  • main (aggregator)
    • java module
    • js (node) module

You can see the same coverage reported on main and java modules, and no coverage for the js one.

I'm using the latest versions of jacoco, jacoco-maven-plugin and Sonar's Java Plugin.

Here are the relevant build log fragments from mvn sonar:sonar -- all seem to be in order:

$ 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

Is this a bug in Sonar's Java Plugin? I think it's highly unlikely that metric reported by sonar is correct when 3 other tools configured by different people consistently show different values.


回答1:


Here is how is computing the "Unit Tests Coverage" measure :

  • NUMBER_OF_LINES = number of lines + number of conditions.
  • COVERED_LINES = NUMBER_OF_LINES - (number of uncovered lines + number of uncovered conditions.

COVERAGE = (100 * COVERED_LINES) / NUMBER_OF_LINES.




回答2:


It seems like the coverage metric has fixed itself. It now reports correct values -- incidentally we've upgraded JDK to latest patch version (8u92) the same day.

This suggests the JaCoCo sensor works wrong depending on JRE, but needs more investigation.



来源:https://stackoverflow.com/questions/36942950/sonar-reports-different-line-and-branch-coverage-than-idea-eclipse-maven-and-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!