Reputation: 21
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.
Straight forward from start to end
One false for 1st 'if'
second false for 2nd 'if'
My question is:
Upvotes: 2
Views: 3684
Reputation: 691
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:
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.
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 :-
Upvotes: 3
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