声纳中的代码覆盖率和线路覆盖范围有什么区别

时间:2012-07-19 13:12:30

标签: code-coverage sonarqube

我知道线路和分支机构覆盖范围之间有什么区别,但代码覆盖率和线路覆盖范围之间有什么区别?以前的指令是否覆盖?

2 个答案:

答案 0 :(得分:30)

覆盖范围是线条和分支覆盖范围的微妙;-)混合。

您可以在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)

答案 1 :(得分:2)

要扩展答案,您只能查询声纳这些术语:

  1. conditions_to_cover
  2. uncovered_conditions
  3. lines_to_cover
  4. uncovered_lines
  5. 然后您可以使用以下公式转换为上述条款:

        var cityName = String()
    
        if let cityAnno = annotation as MGLAnnotation! {
    
            cityName = String(stringInterpolationSegment: cityAnno.title!)
    
        }
    
    cityLabelName.text = ("\(cityName), \(county)")
    

    您可以使用Sonar Drilldown或REST API获取上面的指标值:

    CT + CF = conditions_to_cover - uncovered_conditions
    2*B = conditions_to_cover
    LC = lines_to_cover - uncovered_lines
    EL = lines_to_cover
    

    此博文包含其他信息:http://sizustech.blogspot.com/2015/10/making-sense-of-sonar-qube-stats-like.html