问题描述
我有一个多模块Android项目,并且发现jacoco报告的内容与Sonarqube报告的内容之间存在差异.该项目还是一个多口味项目,可生成许多不同的变体.我正在使用此插件来帮助我生成所有任务.这些任务会为每个变体生成一个单独的报告.
I have a multi-module Android project and I'm seeing a discrepancy between the coverage that jacoco reports and what Sonarqube reports.The project is also a multi-flavor project that generates a lot of different variants. I am using this plugin to help me generate all of the tasks. The tasks generate an individual report for each variant.
运行我的jacoco报告时,我看到以下内容:
When I run my jacoco reports I see this:
当我运行声纳扫描仪时,我看到以下内容:
When I run the sonar scanner i see this:
我的项目中有一些例外情况,但是即使没有这些例外情况,覆盖范围%s也不匹配.
I have some exclusions on my project,but even without them the coverage %s don't match.
我觉得我可能没有提供与
I feel like I may not be providing the same bytecode as hinted in this question:
这是我的相关信息:声纳版本5.6.
Here is my relevant info:Sonar Version 5.6.
越野跑者
plugins { id "org.sonarqube" version "2.0.1" }
声纳配置:(位于root build.gradle上)
Sonar config: (on root build.gradle)
sonarqube {
properties {
property "sonar.projectKey", "com.xxx.myApp"
property "sonar.projectName", "Android My App"
property "sonar.projectVersion", "3.0"
property "sonar.java.binaries", "build/classes"
property "sonar.coveragePlugin", "jacoco"
property "sonar.jacoco.reportMissing.force.zero", "false"
}
}
声纳配置(在app/build.gradle上)
Sonar config (on app/build.gradle)
sonarqube {
properties {
property "sonar.sources", "src/main/java"
property "sonar.tests", "src/test/java"
property "sonar.java.tests", "src/test/java"
property "sonar.junit.reportsPath", "build/test-results/myAppGoogleMobileDebug"
property "sonar.java.binaries", "build/intermediates/classes/myAppGoogleMobile/debug"
property "sonar.jacoco.reportPath", "build/jacoco/testMyAppGoogleMobileDebugUnitTest.exec"
property "sonar.coverage.exclusions", coverageExclusions
}
}
在(app/build.gradle)上的Jacoco配置
Jacoco config on (app/build.gradle)
def coverageExclusions = ['**/AEWatchApp.*', '**/**_Factory.*',
'**/QaSettingsActivity.*',
'com/aetn/android/tveapps/activities/**',
'com/aetn/android/tveapps/test/**',
'com/aetn/android/tveapps/app/injection/modules/**',
'com/aetn/android/tveapps/app/injection/components/**',
'com.aetn.android.tveapps.mock/**',
'com/aetn/android/tveapps/databinding/**']
jacocoAndroidUnitTestReport {
csv.enabled false
html.enabled true
xml.enabled true
excludes += coverageExclusions
}
推荐答案
据我所知,分支覆盖率是相同的:两种情况下均为40%,未发现15个.
As far as I can see branch coverage is the same: 40% in both cases, 15 uncovered.
将指令"(如JaCoCo报告的屏幕快照中所示)与其他任何内容进行比较就像是对苹果和橙子的比较-它们不代表同一件事.请参阅 http://www.eclemma.org/jacoco/trunk/doc/counters. html 关于JaCoCo提供的计数器.并且 http://docs.sonarqube.org/display/SONAR/Metric+Definitions关于SonarQube显示的内容.说明涵盖范围仅在JaCoCo中提供.
And comparison of "instructions" (shown in screenshot of JaCoCo report) with anything else is like comparison of apples and oranges - they don't represent the same thing. See http://www.eclemma.org/jacoco/trunk/doc/counters.html about counters that JaCoCo provides. And http://docs.sonarqube.org/display/SONAR/Metric+Definitions about what SonarQube shows. Instructions coverage is presented only in JaCoCo.
行"(SonarQube屏幕快照中显示的"27.1%")与指令"不同:单行代码通常包含许多字节码指令.因此,例如,如果您总共在10行中有100条指令,并用20条指令覆盖了1行,那么错失的指令占80%,而错失的占90%.
"lines" ("27.1%" shown in screenshot of SonarQube) is not the same as "instructions": Single line of code usually contains many bytecode instructions. So for example if in total you have 100 instructions in 10 lines and cover 1 line with 20 instructions, then missed instructions 80%, but missed lines 90%.
因此,总的来说,没有任何差异,或者至少没有出现在您的屏幕截图中.
So all in all, there is no discrepancy or at least it is not shown on your screenshots.
这篇关于Sonarqube的总体覆盖范围与jacoco报告的覆盖范围不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!