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

Hi,

We are noticing the code coverage percentage is less in sonar portal compared to local for web projects verified all the configurations are good any help/suggestions on this issue ?

Thanks.

Hi,

This dusty-but-still-relevant blog post may help:

 
Ann

Hi @ganncamp ,

Thanks for your reply the version i notice in the link was project version ?

If not could you please help me where do i need to update the version specified ?

Thanks.

Hi,

That blog post has a bit of age on it. You can ignore all the version numbers in it; the functionality is now in place for all languages.

 
HTH,
Ann

Okay, but we have added required exclusion list in the sonar cloud for the project manually still the coverage was not same as the local. when i went through the blog information it says exclusions are required .

Hi,

Thanks for the added detail.

For files included in a coverage report, we go 100% by the report. So I assumed the differences lie in SonarQube showing as uncovered files that you’ve ignored locally?

 
Ann

Yes, you are correct for the excluded patterns in sonar we are seeing it as uncovered however its not required it meant to be excluded. here the missing part is with the same reports the coverage % differs from local and sonar cloud.

Hi,

To make sure I understand

You’re saying your coverage report shows one coverage % for a given file and SonarCloud shows a different overall number?

 
Thx,
Ann

You are right the code coverage % is showing less on sonar

Hi,

And is the coverage % lower overall, or for individual files?

 
Ann

Its for lower overall % .

Hi,

Then this sounds like exactly what’s described in that blog post I sent.

 
HTH,
Ann

Could you please specify me more on that point will be clear and helpful

Hi,

What did you understand from the blog post?

 
Ann

Yes as per the blog clearly described that number of executed lines (unit tests) will show the coverage and other code will not calculate the %

Hi,

What the blog post is trying to tell you is that SonarQube will include files your coverage report leaves out. That can result in a lower coverage % in SonarQube than you see in your report (locally).

If you want to remedy that, you should set coverage exclusions on the files that your report omits.

 
HTH,
Ann

Yes we have added required exclusions but after this even still its the issue exists this is variating 10% less comparing to local.

We have same issue with Android (kotlin) repo you have closed the thread.

Hi,

Would you care to provide specifics?

 
Ann

You mean what are the exclusions added in sonar for web repos ?