3

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.stack.imgur.com/yCnms.png Any ideas?

Brett VanderVeen
  • 893
  • 1
  • 11
  • 16

2 Answers2

4

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.

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • Hey Shaun, thanks for the reply. If you notice... the total coverage when calculated always tends between the two extreme values (lowest and highest). Why, in my situation, is the total coverage so much more than any of the both the package's coverage? Even code branching wouldn't explain what I am seeing. Can you explain the calculation using my situation? – Brett VanderVeen Feb 17 '12 at 14:37
  • [This screenshot](http://i.stack.imgur.com/OQOqJ.png) shows the information necessary to calculate the coverage how you did, but it still doesn't work. First, why aren't all packages displayed on the screen shown in the screenshot on the Question? Second, why does the coverage still not add up? I get ~94.6% when calculated manually, and actually our total coverage went up to 96.1% according to Sonar. – Brett VanderVeen Feb 17 '12 at 15:38
  • The coverage value alone does not just use line coverage (the numbers even rounded to 1 decimal don't make sense unless there is another factor involved) but also t/f branch coverage, but that number is not displayed but as complexity is around 20 then I'd expect the number of branches to be in that approximately double that. As for why coverage not showing perhaps the class has no measurable code or wasn't tested - I only have 1/2 the picture. – Shaun Wilde Feb 18 '12 at 03:27
2

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%

Brett VanderVeen
  • 893
  • 1
  • 11
  • 16
Vimil Saju
  • 345
  • 3
  • 7