Brett VanderVeen
Brett VanderVeen

Reputation: 904

Sonar Code Coverage Analysis Doesn't Add Up

Maybe this is due to my own misunderstanding of what in Sonar is being analyzed, but at the Component level Sonar is reporting a much higher percentage of code coverage than what appears to be possible given the results at the package level. May I point your attention to the attached screenshot... See: https://i.sstatic.net/yCnms.png Any ideas?

Upvotes: 3

Views: 3174

Answers (2)

Vimil Saju
Vimil Saju

Reputation: 345

The screenshot only shows code coverage for packages

com.gfs.transportation.transprointegration.filewatcher
com.gfs.transportation.transprointegration.filewatcher.impl

If the Code coverage for the below components are 100%

com.gfs.transportation.transprointegration
com.gfs.transportation
com.gfs
com

Then total coverage will be (87.9 + 89.2 + 100 + 100 + 100 + 100) /600 which equals 96.183%

I am thinking if a package has no classes under it then the coverage of the package is 100%

Upvotes: 2

Shaun Wilde
Shaun Wilde

Reputation: 8378

It all depends on the size of the classes and how they contribute to the coverage of the module as a whole

  • If Class A had 10 lines of code at 90% coverage then that is 9 lines covered
  • If Class B had 1000 lines of code at 60% coverage then that is 600 lines covered

The coverage overall is 60.3% (609/1010)

But if

  • If Class A had 10 lines of code at 60% coverage then that is 6 lines covered
  • If Class B had 1000 lines of code at 90% coverage then that is 900 lines covered

Now the coverage overall is 89.7% (906/1010)

Then you have to take into account of whether the coverage for filewatcher also includes the coverage metrics of filewatcher.impl - which I suspect it might do.

Finally you haven't mentioned if the number you are displaying is branch/line or a combination of both which the link provided in the comment implies is possible, if the latter then the combinations involved start to make my head hurt.

Upvotes: 4

Related Questions