本文共 722 字,大约阅读时间需要 2 分钟。
本文转载至:
100% coverage sounds great, but is it c0, c1, c2, c3 or path coverage ? If you do not know, here is the answer:
- C0 = every instruction
- C1 = every branch if(i=1) a; even if there is no actual instruction in the i!=1 path it needs 2 tests
- i = 1
- i != 1
- C2 + C3 ~= is every condition inside an ‘if’ is once true and once false (personally, i could not care less…)
- C4: Path-coverage = every possible path was taken, if(a) x else b; if(c) y requires 4 tests
- a true c true
- a true c false
- a false c true
- a false c false
Try to aim for ~95% C0 and ~70% C1. C2 and C3 in my opinion add no value(except that they cover more paths) and C4 is often not possible, since a loop can have infinite paths (go through 1,2,3,4… times).