How many test cases are necessary to cover all the possible sequences of statements (paths) for the following program fragment?

if (condition 1)

    then statement 1

else statement 2


if statement 2

    then statement 3


The answer is supposed to be 3 but I don't know why? can someone draw a diagram or explain this? ISTQB Foundation Level Paper #3 no. 37.

  • 1
    Could you use brackets to represent any nesting ? Jun 14, 2017 at 14:55

2 Answers 2


It's three paths. If I express it via a more c# syntax you get this:

if (condition1)
     statement = statement1;
     statement = statement2;

That gives us 2 paths:

condition1 == true -> statement1
condition1 == false -> statement2

Next, statement 2 is checked for true/false:

if (statement2)
    statement = statement3

So your 3 end points are:

condition1 true -> statement1 (value doesn't matter)
condition1 false -> statement2 true -> statement3
condition1 false -> statement2 false -> statement2
  • This is why having brackets is essential! Now it makes sense. Jun 15, 2017 at 7:40

I think statement coverage is 2. let's take condition1 = a>b condition2 = c>d test case1: a=3,b=1,c=5 and d=3 in this tets case statement 1 and statement 2 are covered testecase2: a-1,b=3,c=5 and d=3 in this case statement 2 and statement 3 are covered i.e. with two test case we can cover all statements so statement coverage is 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.