Code coverage percentage is not same as local for our web projects in sonar

Hi,

You keep saying the coverage numbers don’t match. What files show up as covered in your local report that don’t show up as covered in SonarQube?

Or, if it’s the opposite, what files don’t show up in SonarQube that are ignored by your coverage report? And yes, in this case, you should provide your exclusion settings too, as well as your full 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

web_sonar_analysis.txt (26.3 KB)
Please find the logs attached and sonar.coverage.exclusions below.

wis_webapp/src/**/*test*,src/data/**,src/routes/**,**/*Utils*,src/utils/**,src/redux/slices/**

Hi,

Thanks for the log and the exclusions.

Typing too fast there^. What files show up as uncovered in SonarQube that are ignored by your coverage report?

 
Ann

Yes you are correct still there are more lines uncovered in the sonar project.
The same issue across the projects we are using API (.NET), WEB (js/ts), Android (kotlin).

Hi,

I need specifics. What files are not being ignored for coverage purposes?

 
Ann

You mean which files considered 100% coverage without at loss ? could you please confirm me if i understand it in a right way ?

Hi,

This thread is about coverage not matching because SonarQube counts as uncovered files you think it should ignore.

I need some indication of what files that applies to.

 
Ann

Hi @ganncamp ,

For our android project we can see more difference compared from local, please find the exclusions below.

**/databinding/*Binding.*,**/R.class,**/R$*.class,**/BuildConfig.*,**/Manifest*.*,android/**/*.*,**/*$ViewInjector*.*,**/*$ViewBinder*.*,**/Lambda$*.class,**/Lambda.class,**/*Lambda.class,**/*Lambda*.class,**/*_MembersInjector.class,**/Dagger*Component*.*,**/*Module_*Factory.class,**/di/module/*,**/*_Factory*.*,**/*Module*.*,**/*Dagger*.*,**/*Hilt*.*,**/*MapperImpl*.*,**/*$ViewInjector*.*,**/*$ViewBinder*.*,**/BuildConfig.*,**/*Component*.*,**/*BR*.*,**/Manifest*.*,**/*$Lambda$*.*,**/*Companion*.*,**/*Module*.*,**/*Dagger*.*,**/*Hilt*.*,**/*MembersInjector*.*,**/*_MembersInjector.class,**/*_Factory*.*,**/*_Provide*Factory*.*,**/*Extensions*.*,**/*Fragment*.*,**/*Activity.*,**/local_db/*,**/databinding/*,**/imei/*,**/base_activity/*,**/barcode/*,**/worker/*, **/shared/*,**/domain/*,**/**/splash/*,**/syncDialog/*,**/generated/**,**/**Dialog*.*,**/**Screen.*,**/**Adapter.*,**/repository/*,**/**Factory.*, **/FlexFeatureApplication.*,**/model/**,**/AuditorAncillaryFields.*,**/CounterAncillaryFields.*,**/AuditorItemQuantity.*,**/AsteriskPasswordTransformationMethod.*,**/PreferenceManager.*

Hi,

That’s a lot of data.

Can you identify a few files from your screenshots that should be excluded but are not, along with the portion of the exclusion pattern you believe should be excluding them?

 
Thx,
Ann

No, these files has test cases included but not added in the exclusion still it is showing as uncovered lines of code.

Hi,

While I appreciate all data you provided in your previous post, it’s just too much for me to process. To proceed, please identify a handful of files from one of your screenshots and specify which clause in the exclusion you believe should have applied to them.

 
Thx,
Ann

@ganncamp ,

please find the details below for few files right now.

Hi,

And what part of the exclusion should have covered these files?

We are only receiving code coverage % from this particular folder repo/src/main/java/com/ for the project.

The above image i have sent is not belonged to the folder i have mentioned here.

Hi,

Which part of this exclusion should have prevented AuditTagUseCase.kt from being counted for coverage?

 
Ann

The file i have sent is not excluded it has test cases which has uncovered lines of code. all in all is the line coverage is not matching from local.

Hi,

Uhm… Files are treated either as test files or as program source code.

 
Ann

If you take look at the extension of the files in the screenshot those are test files ‘.kt’ and identified as there are number of lines of code from the files.

Hi,

I’m pretty lost at this point.

This thread started with ‘the coverage in SonarQube doesn’t match the coverage % we see locally’. I’ve asked multiple times that you identify what files should be excluded from coverage calculations, and what part of your exclusion string you think should have excluded them. I don’t perceive direct answers to my questions in any of your responses.

I’m not sure I can help you.

 
Ann

Hi @ganncamp ,

I have sent you the list of exclusions and uncovered lines form the lines may i know which is unclear from you ?

The image i have sent is excluded files and still it is calculating the lines of code and showing as uncovered.

Thanks.