How many test cases are necessary to cover all the possible sequences of statements (paths) for the following program fragment? Assume that the two conditions are independent of each other: if (Condition 1) then statement 1 else statement 2 fi if (Condition 2) then statement 3 fi
-
2 Test Cases
-
3 Test Cases
-
4 Test Cases
-
Not achievable
A
Correct answer
Explanation
With two independent conditions in nested if statements, we need 2 test cases: (1) Condition 1 true, (2) Condition 1 false. When Condition 1 is false, we never reach Condition 2 due to the else branch. When Condition 1 is true, we always execute statement 3 regardless of Condition 2. Thus only 2 paths are possible.