[英]SonarQube + Jacoco Coverage Discrepancies
I have been using Jacoco to analyze the Code-Coverage of my team's maven project for almost 3 months now. 我已经使用Jacoco来分析我团队的Maven项目的代码覆盖率近三个月了。 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. 在过去的几天中,我们已经开始尝试对该项目进行SonarQube分析。 The issue we are running into is that the coverage shown in SonarQube is drastically different from what Jacoco is displaying for us.
我们遇到的问题是,SonarQube中显示的覆盖范围与Jacoco为我们显示的覆盖范围完全不同。
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 . 我已经研究过此问题,并在线阅读了一些解决方案,可以在此处的URL上找到与我们所遇到的问题最相似的问题。 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: 在我们正在处理的
pom.xml
文件中,我在properties文件夹中添加了以下几行:
<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. 这些是我在网上找到的,告诉我们如何配置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%
. 例如,在Jacoco.html文件中,我们的分支覆盖率为
9.44%
但在SonarQube中,条件覆盖率为10.00%
。
The same issues happen with the line coverage which is in Jacoco.html 13.76%
as opposed to 11.1%
in SonarQube. Jacoco.html中的线路覆盖率为
13.76%
,而SonarQube中的11.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分析并逐包比较所分析的内容,我能够找出所使用的设置的问题。
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. SonarQube正在分析整个存储库,显示的默认覆盖率报告不仅反映了使用
jacoco.xml
而且还查看了其他类型的代码。
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. 为了查看准确的代码覆盖率,我必须将SonarQube分析中的查找位置更改为专门包含Java代码的目录,从而在两个服务之间调整覆盖率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.