local jacoco code coverage % and sonarqube coverage % is different, why?
in local, jacoco report shows 72% instruction coverage and 52% for branch coverage.
but in sonarqube, totatl coverage is 45%, why that discrepency… how can we calculate the actual local jacoco report which match with sonarqube.
can someone help me with the formula to get the coverage pls?
hopw to calculate exactly with the above metrics in screenprint…
Coverage = (CT + CF + LC) / (2*B + EL) - is this applicableto use only in sonarqube or local jacoco report
sorry, but needed more info. how can we achieve? does jacoco exclusion vs sonar exclusion must be same or we need to alter in sonarqube?
Hi,
If JaCoCo is omitting files from its report because there are no tests on them and you want your coverage numbers to match, you’ll need to create SonarQube coverage exclusions. That said, it’s really not the best idea to just ignore it when files aren’t covered.
HTH,
Ann
tried giving the way you suggested, sonar.coverage.exclusions were updated instead of sonar.exclusions… both retrieved the same %. no change in coverage. discrepency exists.
Hi,
What exclusions did you set? Do you believe they worked?
Ann
Hey Ann
sharing you the screenshot of project.gradle which says exclusion list, which developer wants to add in pipeline to get the expected coverage/result… added this list in sonar.coverage.exclusions property… but still no difference with sonar.exclusion property… resulted same 48%.
Hi,
How does that excludes
definition get translated into a coverage exclusion?
Care you share your analysis log?
The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.
This guide will help you find them.
Ann
shared you the analysis log. please pin point where am i doing wrong related to coverage % discrepancy what needs to focussed to atleast match near the local jacoco coverage%.
sonarlognew.txt (9.4 KB)
Hi,
Thanks for the log. Now can I have a screenshot of a file or directory that should be excluded from coverage calculations, with a coverage value? E.G.
Ann
sonar.properties (i have excluded org details part)
sonar.core.serverBaseURL: sonar url
sonar.cpd.exclusions: **/domain/*
sonar.coverage.exclusions: *.sh,**/*Mock*.*,**/mock/*.*,**/BuildConfig.*,**/Manifest*.*,**/R.class,**/R$*.class,**/BuildConfig.*,**/*Manifest*.*,androidx/**/*.*,**/android/**/*.*,**/androidx/**/*.*,**/databinding/**/*.*,**/Databinder$*.*,**/BR.class,**/ui*.*,**/ui/*.*,**/ui/*,**/views/*,**/remoteconfig/*,**/designsystem/*,**/biometric/*,**/customview/*,**/scanmodule/*,**/core/common/*,**/feature/receiving/*,**/feature/audits/*,**/core/test/*,**/core/session_manager/*,**/core/database/*,**/core/analytics/*,**/core/navigator/*,**/core/appmonitor/*,**/core/appupdate/*,**/adapter/*,**/viewholder/*,**/interceptor/*,**/*Fragment.*,**/MoreScreenUseCase.*,**/LoginAnalyticsImpl.*,**/LoginAnalyticsUtils.*,**/LoginErrorHandler*.*,**/LoginBaseHelper*.*,**/LoginAnalytic*.*,**/ToolbarHelper*.*,**/VantusApplication.*,**/CartsLocalDataSource*.*,**/MoreAnalytic*.*,**/feature/account/utils/*,**/navigation/*,**/*Activity.*,**/data/carts/*,**/domain/carts/*,**/feature/carts/*,**/core/network/*,**/core/appconfig/*,**/core/datastore/*
sonar.java.coveragePlugin: jacoco
sonar.coverage.jacoco.xmlReportPaths: build/reports/jacoco/allDebugCoverage/allDebugCoverage.xml
sonar.java.binaries: '**/build/tmp/kotlin-classes/prodDebug'
sonar.java.libraries: ../master-pipeline/libs
sonar.java.source: 11
sonar.projectDescription: test
sonar.projectKey: xx
sonar.projectName: xx
sonar.sourceEncoding: UTF-8
sonar.sources: app/src/main,core/*/src/main,data/*/src/main,domain/*/src/main,feature/*/src/main
sonar.tests: core/common/src/test,core/scanmodule/src/test,core/database/src/test,core/search/src/test,core/session-manager/src/test,data/*/src/test,domain/*/src/test,feature/*/src/test
==============
in sonar.sources and tests → i i gave absolute path instead of wildcards, both retrieved the same results, so using ** wildcards
Hi,
Thanks for the screenshot and for re-stating your exclusions. That was helpful.
When I look at your screenshot, I see
- app/src
- core
- data
- domain
- feature
For the first one, app/src
there’s no relevant exclusion. For the other four directories, there are multiple sub-directory exclusions:
**/data/carts/*,
**/domain/carts/*,
**/feature/receiving/*,
**/feature/audits/*,
**/feature/carts/*,
**/feature/account/utils/*,
**/core/network/*,
**/core/appconfig/*,
**/core/datastore/*,
**/core/common/*,
**/core/test/*,
**/core/session_manager/*,
**/core/database/*,
**/core/analytics/*,
**/core/navigator/*,
**/core/appmonitor/*,
**/core/appupdate/*,
That implies that, e.g. under core
there is some other directory (at least one) that should be counted for coverage. Otherwise, instead of excluding 11 subdirectories individually, you’d have just excluded the whole thing: **/core/**/*
. So unfortunately, the screenshot doesn’t conclusively show me anything that should have been excluded for coverage but wasn’t.
Can you maybe drill into core
and give me a screenshot of that?
Thx,
Ann
you are right, there 5 modules and under these modules we have sub-modules except app.
shared the core and its sub modules. only some has test files , later in future test files will be added to other sub-modules too.
Hi,
Thanks for the screenshot.
What I see is that some exclusions worked:
**/core/appconfig/*,
**/core/appmonitor/*,
**/core/appupdate/*,
**/core/test/*,
And the rest did not. And I’m stumped as to why. So I’m going to flag this for more expert eyes.
Ann
Sure Ann, this needs to be fixed or concluded with a good note so that we can have the discrepencies less to be matched somewhat with the local jacoco with sonarqube analysis… Thanks for your patience and effort for this analysis… expecting to fix it as soon as possible.
Hi @Iswaria ,
I think the issue is coming from your exclusion patterns. The syntax to exclude a folder and all its children recursively is to use double star:
sonar.coverage.exclusions=**/core/**
instead of:
sonar.coverage.exclusions=**/core/*
Hey Henry and Ann
do i need to follow on anything to fix this? please let me know… i will try that method
Hi,
i wanted to inform everyone that i have fixed my issue by own
error: sonarqube is showing discrepencies with local jacoco report.
it is obviously due to exclusions property. watch your exclusions list carefully…
i have changed sonar.exclusions to sonar.coverage.exclusions
Fix: earlier i have added exclusion list as per developer’s gradle script eg: /core/appupdate/
in my case, this end up large % discrepencies, so i tried using the below method and it worked perfectly fine for me.
before ==> **sonar.coverage.exclusions: */core/appupdate/ ** (wildcards)
after ==> sonar.coverage.exclusions: /core/appupdate/ ** / * . * (wildcards)
(i have give given spaces becos, editor is not allowing me to add * )
i hope this helps someone like me who is a newbie to sonarqube.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.