Claudiu Barbulescu
Claudiu Barbulescu

Reputation: 11

ISTQB-Whitebox testing: Exercises for Statement and Branch Coverage

I am interesting to understand Statement Coverage and Branch(Decision coverage). I have studied from the internet but I am not sure if I am understood in the best way.

I resolved the below exercises, please could you tell me if I resolved in the correct way?

Example1:

Consider the following pseudo code:     

1.  Begin
2.  Read Gender
3.  __Print “Dear”
4.  If  Gender = ‘female’
5.  Print (“Ms”)
6.  Else
7.  _Print (“Mr”)
8.  Endif 
9.  End 

How many test cases are needed to achieve 100 per cent decision coverage?

A) 1
B) 2
C) 3
D) 4

I think that for the above example the answer is 2, but I am not sure.

I proceed in this way: Branch Coverage: It covers both the true and false conditions.

TC1:  Read Gender==Female, so is True, it’s cover lines: 1,2,3,3,5 and 9

TC2: Read Gender !=Female, so is False, it’s cover lines: 1,2,3,4,6,7,8 and 9

So, to cover Branch Coverage is need 2 Test Cases.

Example2:

Consider the following pseudo code:     

 1.Begin 
 2.Input X, Y
 3.If X > Y
 4. __Print (X, 'is greater than', Y)
 5. Else 
 6. __Print (Y, is greater than or equal to', X)
 7. Endlf 
 8. End

What is the minimum number of test cases required to guarantee both 100% statement coverage and 100% decision coverage?

Number of correct answers: 1

A) Statement coverage = 3, Decision coverage = 3
B) Statement coverage = 2, Decision coverage = 2
C) Statement coverage = 1, Decision coverage = 2
D) Statement coverage = 2, Decision coverage = 1

I think the answer is: Statement coverage = 2, Decision/Branch coverage = 2

For 100% Statement Coverage:

TC1: X=5 and Y=4, it is true and will print the text from line 4

TC2: X=4 and Y=5,  is false and will print the text from line 6

So, Statement Coverage is 2. In this way all the lines are covered.

For 100% Branch Coverage:

I think 2 TCs are needed to cover branch testing, and the same TC’s as for Statement coverage can be used. So, Branch is also 2.

I proceed correctly?

Thank you

Upvotes: 1

Views: 3622

Answers (1)

Ioana
Ioana

Reputation: 21

1) Here is a diagram to make it easier to see the running path: Gender question

As you need to go both options for the condition/question - the correct answer is 2 .

2) For the second problem the graph is : Graph for x,y problem

As in the previous question the DC is 2 and also the statement coverage = 2 ( u need to pass right branch and left branch to cover all statements)

You did answer them corectly.

Upvotes: 2

Related Questions