5

I have seen the following question in an ISTQB - Foundation Level sample paper.

Q. 12: If the pseudo code below were a programming language ,how many tests are required to achieve 100% statement coverage?

  1. If x=3 then
  2. Display_messageX;
  3. If y=2 then
  4. Display_messageY;
  5. Else
  6. Display_messageZ;
  7. Else
  8. Display_messageZ;

Answers
A. 1
B. 2
C. 3
D. 4

I believe that the answer is 2 because you can cover all the Statements by covering the following paths.

  • A,B,C,E,D,G
  • A,B,F,G

Flowchart for the question

However, many web sites (please find a list of sites at the end) say that the answer is 3.

I have two questions :

  • Is there anything wrong with my flowchart?
  • Why is my answer incorrect?

Links to the places where it says that 3 is the correct answer

  1. Fun with Testing
  2. Testing_Manual_Automation
  3. Software Testing Cafe
  4. FYI Center
  5. Patashala.com

5 Answers 5

5

Is there anything wrong with my flowchart?

Yes and no. It is correct functionally: it describes exactly what the code is supposed to do. However, in code, Display_messageZ is called in two places (instead of one, as in your chart).

Why is my answer incorrect?

Because you follow the chart instead of the code, you miss the second call to Display_messageZ to achieve full statement coverage. It's the same statement, but it is still a different line of code so they both need to be executed with this type of coverage.

2

The answer for this question is 3. Here's why,

There are 2 if statements here. Each if statement has 2 possible out comes. Hence for each if statement 2 test cases would be required.

In the case mentioned above the if statements are nested, i.e., 1 if statement is within another if statement.

So for the first if statement:

Case 1: If condition true, display message x and go inside the nested if statement (continue to Case 3).

Case 2: If condition false, skip nested if statement and display message z.

Case 3: If nested condition true, display message y.

Case 4: If nested condition false, display message z.

Here, there are 2 different else statements for the nested if statements. So to cover the else condition(statement) of the inner if statement you will need one additional test case which makes it 3 cases in total.

In case of nested if conditions my usual approach is total cases = number of if statements + 1

3
  • I guess you talk of the branch/decision/path coverage here. In that case, your answer is correct. To cover all the branches/decisions/paths one needs 3 test cases. However, you can cover all the statements(istqb.guru/…) in 2 test cases. Please let me know what you think. Dec 12, 2016 at 9:28
  • I updated my answer. I guess that should clarify your doubt. Dec 12, 2016 at 10:27
  • Yep, now it is clear Dec 12, 2016 at 10:31
1

Correct flow chart --

enter image description here

Answer is C = 3

  1. A,B, F,G
  2. A,B, C, E, D, F, G
  3. A, B,C, E, F, G
0

I think that this is the right chart and you have got 3 paths to cover all statementsenter image description here

-1

Statement 6 and statement 8 will be considered as one. Statement 2 and statement 4 are two separate statement. That's why statement coverage will be 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.