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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)
回答2:
To expand on the answer, you can only query sonar for these terms:
- conditions_to_cover
- uncovered_conditions
- lines_to_cover
- uncovered_lines
And then you can covert to the terms above using these equations:
CT + CF = conditions_to_cover - uncovered_conditions
2*B = conditions_to_cover
LC = lines_to_cover - uncovered_lines
EL = lines_to_cover
You can use the Sonar Drilldown or REST API to get the metric values above:
http://my.sonar.com/drilldown/measures/My-Project-Name?metric=line_coverage
http://my.sonar.com/api/resources?resource=55555&metrics=ncloc,conditions_to_cover,uncovered_conditions,lines_to_cover,uncovered_lines,coverage,line_coverage,branch_coverage,it_conditions_to_cover,it_uncovered_conditions,it_lines_to_cover,it_uncovered_lines,it_coverage,it_line_coverage,it_branch_coverage,overall_conditions_to_cover,overall_uncovered_conditions,overall_lines_to_cover,overall_uncovered_lines,overall_coverage,overall_line_coverage,overall_branch_coverage
This blog post has additional information: http://sizustech.blogspot.com/2015/10/making-sense-of-sonar-qube-stats-like.html