Joh*_*n V 24 metrics code-coverage
据说语句覆盖确保代码中的每个语句至少执行一次.据说
决策/分支覆盖测试是测试决策的每个分支/输出,即将执行假/真分支中的所有语句.
但是不一样吗?在Statement覆盖中我需要执行所有语句,所以我想它只能通过运行所有可能的方式来完成.我知道我在这里遗失了一些东西..
小智 38
The answer by Paul isn't quite right, at least I think so (according to ISTQB's definitions). There's quite significant difference between statement, decision/branch and condition coverage. I'll use the sample from the other answer but modified a bit, so I can show all three test coverage examples. Tests written here gives 100% test coverage for each type.
if(a || b)) {
test1 = true;
}
else {
if(c) {
test2 = true
}
}
Run Code Online (Sandbox Code Playgroud)
We have two statements here - if(a||b) and if(c), to fully explain those coverage differences:
This way we executed each and every statement.
branch/decision coverage needs one more test:
That way we have all the branches tested, meaning we went through all the paths.
condition coverage needs another test:
That way we have all conditions tested, meaning that we went through all paths (branches) and triggered it with each condition we could - first 'if' statement was true in first test because of a=true triggered it and in the last test because b=true triggered it. Of course someone can argue that case with a=true and b=true should be tested as well, but when we will check how 'or' works then we can see it isn't needed and also variable c can be of any value as in those tests it is not evaluated.
At least I interpreted it this way. If someone is still interested :)
EDIT: In most sources I found lately decision/branch coverage terms are equivalent and the term I described as decision coverage is in fact condition coverage hence that update of the answer.
mur*_*ish 17
如果测试具有完整的分支覆盖,那么我们可以说它也具有完整的语句覆盖率,但反之亦然.
100%分支覆盖率=> 100%的声明覆盖率
100%的声明覆盖率并不意味着100%的分支覆盖率
原因是除了执行所有语句之外的分支覆盖,我们还应验证测试是否执行所有分支,这可以解释为覆盖控制流分支中的所有边
if(a){
if(b){
bool statement1 = true;
}
}
Run Code Online (Sandbox Code Playgroud)
a = true,b = true将给出100%的语句覆盖率,但不提供分支覆盖率
在分支覆盖中,我们需要覆盖所有边缘,我们在上面图像中显示为红线的语句覆盖中遗漏了这些边缘
好问题。我经常使用的解释是,没有 else 分支的 if 语句仍然有一个不可见的“空”else 语句:
简单的语句覆盖只是坚持认为所有实际存在的语句都被真正执行。
分支覆盖坚持认为,即使是不可见的 else 分支也会被执行。
没有 default-case 的 switch 语句和重复直到循环也会出现类似的情况。分支覆盖要求执行default-case,并且repeat-until至少执行两次。
代码示例:
if (passwordEnteredOK()) {
enterSystem();
}
/* Invisible else part
else {
// do nothing
}
*/
Run Code Online (Sandbox Code Playgroud)
通过声明覆盖,您只需检查是否使用正确的密码即可使用系统。通过分支机构覆盖,您还可以测试使用不正确的密码将无法进入系统。
| 归档时间: |
|
| 查看次数: |
41727 次 |
| 最近记录: |