参考:
代码覆盖率浅谈 - CoderZh - 博客园 (cnblogs.com)
100% code coverage! (frankel.ch)
代码覆盖率 ——语句覆盖 Statement Coverage、分支覆盖 Branch Coverage、 路径覆盖 Path Coverage的区别_zhuyutong202的博客-CSDN博客
问题:
Discuss the following topic:
If all the methods in the source code that are tested and 100% All-Branch coverage is achieved, is it still possible for the program to fail?
If you agree, state some best practices to mitigate the risk of program failure.
回答:
Yes, I agree with this topic. Because the 100% branch coverage can’t cover all the stations appearing in the program. For example, there is a program.
We need 2 test cases to cover the 100% branch coverage, a=5, b=5 and a=10, b=10;
However, there are 4 possible return values: 0, 1, 10, 11 in this code, but the branch coverage only tests 2 cases and get the 100%. That is to say, the 100% branch coverage can’t prove these 4 possible return values all are tested, maybe the program will fail when executing the cases that are not be tested. So, if all the methods in the source code that are tested and 100% All-Branch coverage is achieved, it is still possible for the program to fail.
As a result, we should try to get the 100% basis path coverage, which is the most comprehensive and strongest coverage among other coverages such as branch coverage and statement coverage.