SonarQube + Jacoco Coverage Discrepancies

六月ゝ 毕业季﹏ 提交于 2021-01-29 17:57:06

问题


I have been using Jacoco to analyze the Code-Coverage of my team's maven project for almost 3 months now. It has been analyzing and increasing properly as we add more and more tests and everything has been working well.

In the last few days we have begun trying to set up a SonarQube analysis of the project. The issue we are running into is that the coverage shown in SonarQube is drastically different from what Jacoco is displaying for us.

I have looked into this already, and read about some of the solutions online, the problem that seemed most similar to what we were running into can be found at the URL here. But this did not fix the problems we had.

In our pom.xml file we are working on, I have added in the properties folder these lines:

<sonar.coverage.jacoco.xmlReportPaths>./codeCoverage/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<sonar.java.source>8</sonar.java.source>
<sonar.java.libraries>target</sonar.java.libraries>

which are what I have found online telling us how to configure the SonarProperties.

I am not getting any errors, but the code coverage is different.

For example in the Jacoco.html file, we have a branch coverage of 9.44% but in SonarQube the conditional coverage is 10.00%.

The same issues happen with the line coverage which is in Jacoco.html 13.76% as opposed to 11.1% in SonarQube.


回答1:


I was able figure out what was wrong with the setup that we were using, by looking through our SonarQube analysis deeper and comparing package by package what was being analyzed.

SonarQube was analyzing the whole repository, and the default report for coverage that was displayed was reflecting using not only the jacoco.xml but also looking at some code from other types.

To see the accurate code coverage, I had to change where we were looking in SonarQube's analysis, to the directory which housed the Java code exclusively thus aligning the coverage percentages between the two services.



来源:https://stackoverflow.com/questions/57601376/sonarqube-jacoco-coverage-discrepancies

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