2

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 ?
ric
  • 627
  • 1
  • 12
  • 23
user7909104
  • 21
  • 1
  • 2
  • The scope of conditionals in the code does not correspond to those on float chart, as far as I can see. Can you make it more explicit, e..g by indentation,? – jmster Apr 23 '17 at 12:56
  • See here: http://stackoverflow.com/questions/8229236/differences-between-line-and-branch-coverage – Amittai Shapira Apr 24 '17 at 02:15

2 Answers2

2

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.

KeithC
  • 436
  • 1
  • 6
  • 25
1

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

Community
  • 1
  • 1
ric
  • 627
  • 1
  • 12
  • 23