What is the difference between code coverage and line coverage in sonar

Bartosz Radaczyński picture Bartosz Radaczyński · Jul 19, 2012 · Viewed 17.7k times · Source

I know what the difference is between line and branch coverage, but what is the difference between code coverage and line coverage? Is the former instruction coverage?

Answer

Fabrice - SonarSource Team picture Fabrice - SonarSource Team · Jul 19, 2012

Coverage is a subtle ;-) mix of the line and the branch coverage.

You can find the formula on our metric description page:

coverage = (CT + CF + LC)/(2*B + EL)

where

CT - branches that evaluated to "true" at least once
CF - branches that evaluated to "false" at least once
LC - lines covered (lines_to_cover - uncovered_lines)

B - total number of branches (2*B = conditions_to_cover)
EL - total number of executable lines (lines_to_cover)