我对声明和决策覆盖感兴趣并正在研究。
What type of problem will be found with 100% decision coverage that would be missed by 100% statement coverage?
A. A problem that occurs within a loop
B. A problem that occurs in an IF with an ELSE
C. A problem that occurs in an IF without an ELSE
D. A problem that occurs outside a loop
我收到了这个示例问题,我选择正确答案为 B。 因为 100% 的语句覆盖率可确保代码中的每个单独语句至少执行一次。但是,它并不能保证所有决策分支所有可能的真假结果都已被测试。
但是我朋友说正确答案应该是C。
谁能给我解释一下正确答案。
例如,如果您有以下代码片段
输入年龄;
如果年龄>65
显示“你是前辈”
从陈述的角度来看,你有3个陈述,通过将覆盖100%。但是,决策/分支承保范围不包括在内 - 如果年龄为 <65? this is not covered even though statement is 100%
会发生什么决策覆盖范围1:年龄>65 决策覆盖范围 2:年龄 < 65 Testing these both decision cases will cover the tests and will catch that scenario.