zoukankan      html  css  js  c++  java
  • CoverageMeter中关于“line coverage”不准确的解释

    在之前的代码覆盖率浅谈中其实已经谈到了关于行覆盖的缺陷,但由于行覆盖足够简单,还是被广泛使用着。另我惊讶的是,作为一个商业的C++代码覆盖率工具CoverageMeter,它明确指出,不提供行覆盖数据,因为他们认为行覆盖不准确。

    下面是原文:

    CoverageMeter does not support line coverage because this kind of measurement and statistic is not accurate.

    This metric depends on how you format the code

    然后,列举了同样一段代码的4种写法,行覆盖结果千差万别。

    第一种写法,行覆盖率33%

    int main()
    {
        
    HIT   if (truereturn 1;
        
    MIS   foo();
        
    MIS   return 0;
    }

    第二种写法,行覆盖率50%

    int main()
    {
        
    HIT   if (true)
        
    HIT       return 1;
        
    MIS  foo();
        
    MIS  return 0;
    }

    第三种写法,行覆盖率66%

     int main()
    {
        
    HIT   if (true)
       
     HIT       return 1;
        
    MIS   foo(); return 0;
    }

    第四种写法,行覆盖率100%

    int main()
    {
        
    HIT   if (truereturn 1; foo(); return 0;
    }

    其实,要证明行覆盖不准确有很多方法。上面的方法只是其中一种,或许有人还会对上面提到的理由提出反驳,因为他们觉得他们的代码都是遵循一定的代码规范的,像将多个语句写在同一行是绝对不允许的。是的,没错。你能够证明上面的理由不够充分,却无法推翻它的结论。

  • 相关阅读:
    [LeetCode]Binary Tree Level Order Traversal
    [LeetCode]Binary Tree Postorder Traversal
    Netty(六):NioServerSocketChannel源码解析
    Netty(五):ServerBootstrap启动流程
    Netty(四):AbstractChannel源码解析
    Netty(三):IdleStateHandler源码解析
    自定义fastjson对枚举类型的序列化及反序列化过程
    TCP连接过程及报文解析
    Netty(二):数据在ChannelPipeline中的流经
    Netty(一):ByteBuf读写过程图解
  • 原文地址:https://www.cnblogs.com/coderzh/p/1521739.html
Copyright © 2011-2022 走看看