注:转载文章如涉及版权,请通知。原创作品如转载,请注明出处并保持完整。

Test Theory——Coverage Analyze 4: Decision Coverage

上一篇 / 下一篇  2009-05-21 14:52:06 / 个人分类:Testing

DecisionCoverage, 即判定覆盖率,也称为分支覆盖率

它要求在控制流程( if-statement and while-statement)中的每个布尔表达式即判定的真或假都要被测试到至少一次。也就是说,由控制流程而来的每个分支至少被执行一次。

从中知道,对于每个布尔表达式,我们只关心它的最终结果,即真或假,而不会去关心这个布尔表达式的组成,如它是否含有多个逻辑与或者逻辑或。

另外,Decision Coverage包括了Switch语句的各种Cases,异常处理(exception handlers)和中断处理(interrupt handlers)。

从上面我们可以看从,判定覆盖率和语句覆盖率一样的简洁方便,但是却没有语句覆盖率的主要问题。因此,判定覆盖比语句覆盖更加强大,而所需要的测试用例也会更多。

判定覆盖率的主要缺点在于它只考虑一个布尔表达式的真或假,而不在乎布尔表达式的组成。如果一个布尔表达式由多个逻辑表达式组成,则判定覆盖率往往会忽略一些逻辑表达式的影响(即Short-Circuit Operators)。

举例如下:
if (condition1 && (condition2 || condition3))
statement1;
else
statement2;

我们来看布尔表达式:
condition1 && (condition2 || condition3)

如果Condition1为TURE 而且 Condition2也为TURE,则无论Condition3为真还是假,整个布尔表达式都将为真;而当Condition1为FALSE,则无论Condition2或者Condition3为真还是假,整个布尔表达式都将为假。

那有人会问这有什么不妥吗?
Ok.很显然,当condition1为真和condition2为假时,就必须考虑condition3的情况了,因此这其中存在着判定覆盖率无法考虑的地方。
从这我们也可以看出判定覆盖率对某些控制流程仍然不是非常的敏感。

最后我们来看看C++ Test是如何定义Decision Coverage的。
Decision Coverage:
Indicates how many branches in source code control flow passed. Complete, 100% coverage is obtained when every decision at all branching points took all possible outcomes at least once.

C++test considers the following statement types branching points in source code: if-else, for,while, do-while, and switch. C++test does not take into account such dynamic branching points as exception handlers (throw-catch statements).

我们可以看出,C++ Test对于动态分支如异常处理(throw-catch)是不做计算的。









TAG:

 

评分:0

我来说两句

charlie.chow

charlie.chow

积极,乐观,淡定

日历

« 2024-05-16  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 9071
  • 日志数: 36
  • 建立时间: 2009-05-17
  • 更新时间: 2009-06-19

RSS订阅

Open Toolbar