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

前端 未结 2 747
梦谈多话
梦谈多话 2021-02-01 18:36

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?

相关标签:
2条回答
  • 2021-02-01 18:51

    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)
    
    0 讨论(0)
  • 2021-02-01 18:58

    To expand on the answer, you can only query sonar for these terms:

    1. conditions_to_cover
    2. uncovered_conditions
    3. lines_to_cover
    4. 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

    0 讨论(0)
提交回复
热议问题