Software Development and Project Management
The truth values of a, b and c can be chosen independently of each other. For the code 'if (a) { S1; } if (b) { S2; } if (c) { S3; }', what is the minimum number of test cases needed to achieve branch coverage (executing both the true and false outcomes of every decision at least once)?
- A1
- B2
- C8
Show answer and explanation
Answer: B. 2
Each of the three decisions must be taken both ways, true and false. With the two test cases (a, b and c all true) and (all false), the true and false outcomes of each decision are each executed once, so the minimum is 2. A single test case (all true) executes all the statements S1 to S3 and so achieves statement coverage, but the false branches (the paths that do nothing and move on) are not executed. 8 is the number of all 2³ = 8 combinations of true and false.
- A. A single all-true run achieves statement coverage, but the false branch of each decision is never executed.
- B. Correct. The all-true and all-false runs take each decision both ways once.
- C. This is the number of all 2³ = 8 combinations of true and false; branch coverage does not require that many.
Continue: 9 more Software Development and Project Management questions