user7909104
user7909104

Reputation: 21

What is branch coverage?

I am preparing myself for ISTQB exam and I came across this question.

For the code fragment given below, which answer correctly represents minimum tests required for statement and branch coverage respectively?

Discount rate=1;
Fare = 1000;
If ((person == “senior citizen”) and (“travel month = January”))
Bonuspoints = 100+Bonuspoints
If (class==”first”)
discountRate = .5;
Fare = fare * discountRate;
  • a. Statement Coverage = 1, Branch Coverage = 2
  • b. Statement Coverage = 2, Branch Coverage = 2
  • c. Statement Coverage = 1, Branch Coverage = 3
  • d. Statement Coverage = 2, Branch Coverage = 4

Answer is A

But my answer is C the reason is flowchart I draw for it given below.

  1. Straight forward from start to end

  2. One false for 1st 'if'

  3. second false for 2nd 'if'

Flow chart

My question is:

  1. Should we draw an edge 'explicitly' for 'false' condition, if it is not given in question itself.
  2. How branch coverage is 2 here ?

Upvotes: 2

Views: 3684

Answers (2)

Richa
Richa

Reputation: 691

To calculate Statement Coverage

Find out the shortest number of paths following which all the nodes will be covered.
Here in this Flow chart I have defined Nodes and edges as below:

  1. 1,2 3, etc are Nodes
  2. A, B, C etc are Edges

With path 1A-2B-3C-4D-5G-6G-7H, all nodes 1,2,3... 7 is covered.
So, Statement Coverage will be 1 as no other path we need here to cover all nodes.

To calculate Branch Coverage

Find out the minimum number of paths which will ensure covering of all the edges.

With path 1A-2B-3C-4D-5G-6G-7H, we have covered 1 side edge in this flow chart (I, J is remaining)

for that path will be

1A-2B-3I-5J  
1A-2B-3C-4D-5G-6G-7H 

By the combining the above two paths we can ensure of traveling through all the paths so correct answer is:-

a. Statement Coverage = 1, Branch Coverage = 2

Flow Chart :-

enter image description here

Upvotes: 3

KeithC
KeithC

Reputation: 456

I believe your diagram/Flowchart is incorrect.

It makes more sense to me that both IF statements will Always be run. A 'False' result in the First IF statement will mean that the code will then execute the 2nd If statement.

Test 1 will cover positive scenarios. Both of your IF statements will be TRUE, meaning a full pass through all positive outcomes of your conditional statements

Test 2 will provide False to the first IF statement, and then again False to the second IF statement, which covers all the negative outcomes of this branch.

Upvotes: 2

Related Questions