1

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

fi

if statement 2

    then statement 3

fi

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
  • 1
    Could you use brackets to represent any nesting ? Jun 14, 2017 at 14:55

3 Answers 3

3

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

if (condition1)
{
     statement = statement1;
}
else 
{ 
     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
1
  • This is why having brackets is essential! Now it makes sense. Jun 15, 2017 at 7:40
0

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

0

There is probably a small error in the content of the task asked by @Kristina ("statement 2" instead of "condition 2"). Assuming the following code below is OK:

if (Condition 1)
  then Statement 1
else Statement 2
fi
if (Condition 2)
  then Statement 3
fi

Flow chart:

Flow chart to the task

For me, the question is not entirely precise, because Statement Coverage is something different than Path Coverage.

To cover all the possible sequences for Statement Coverage we need 2 test cases:

  • TC1: Condition 1 - TRUE, Condition 2 - TRUE
  • TC2: Condition 1 - FALSE, Condition 2 - TRUE or FALSE

To cover all the possible sequences for Path Coverage we need 4 test cases:

  • TC1: Condition 1 - T, Condition 2 - T (A-B-E-F)
  • TC2: Condition 1 - T, Condition 2 - F (A-B-G)
  • TC3: Condition 1 - F, Condition 2 - T (C-D-E-F)
  • TC4: Condition 1 - F, Condition 2 - F (C-D-G)

So I am also confused about supposed correct answer (3).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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