How to calculate Statement, Branch/Decision Coverage
HOW TO CALCULATE STATEMENT, BRANCH/DECISION AND PATH COVERAGE FOR ISTQB EXAM PURPOSE
Statement Coverage: (Find shortest path such that all nodes are covered at-least once)
In this, the test case is executed in such a way that every node is traversed at-least once.Branch/Decision Coverage: (Find shortest path such that all the Edges are covered at-least once)
Test coverage criteria requires enough test cases such that each condition in a decision
takes on all possible outcomes at least once, and each point of entry to a program or
subroutine is invoked at least once. That is, every branch (decision) taken each way,
true and false. It helps in validating all the branches in the code making sure that no
branch leads to abnormal behavior of the application.
Path Coverage:(Find all the paths from source to destination)
In this the test case is executed in such a way that every path is executed at least once.All possible control paths taken, including all loop paths taken zero, once, and multiple
(ideally, maximum) items in path coverage technique, the test cases are prepared based
on the logical complexity measure of a procedural design. In this type of testing every
statement in the program is guaranteed to be executed at least one time. Flow Graph,
Cyclomatic Complexity and Graph Metrics are used to arrive at basis path
How to calculate Statement Coverage, Branch Coverage and Path Coverage?
Draw the flow in the following way-
Nodes represent entries, exits, decisions and each statement of code.
Edges represent non-branching and branching links between nodes.
Example:
Read P
Read Q
IF P+Q > 100 THEN
Print “Large”
ENDIF
If P > 50 THEN
Print “P Large”
ENDIF
Calculate statement coverage, branch coverage and path coverage.
The flow chart is-
Statement Coverage (SC):
To calculate Statement Coverage, find out the shortest number of paths followingwhich all the nodes will be covered. Here by traversing through path 1A-2C-3D-E-4G-5H all
the nodes are covered. So by traveling through only one path all the nodes 12345 are covered,
so the Statement coverage in this case is 1.
Branch Coverage (BC):
To calculate Branch Coverage, find out the minimum number of paths which willensure covering of all the edges. In this case there is no single path which will ensure coverage
of all the edges at one go. By following paths 1A-2C-3D-E-4G-5H, maximum numbers of
edges (A, C, D, E, G and H) are covered but edges B and F are left. To covers these edges we
can follow 1A-2B-E-4F. By the combining the above two paths we can ensure of traveling
through all the paths. Hence Branch Coverage is 2. The aim is to cover all possible true/false
decisions.
Path Coverage (PC):
Path Coverage ensures covering of all the paths from start to end.
All possible paths are-
1A-2B-E-4F
1A-2B-E-4G-5H
1A-2C-3D-E-4G-5H
1A-2C-3D-E-4F
So path coverage is 4.
Thus for the above example SC=1, BC=2 and PC=4.
Memorize these….
100% LCSAJ coverage will imply 100% Branch/Decision coverage
100% Path coverage will imply 100% Statement coverage
100% Branch/Decision coverage will imply 100% Statement coverage
100% Path coverage will imply 100% Branch/Decision coverage
Branch coverage and Decision coverage are same.
Mohit Bhatia
Great !! Thank you
ReplyDeleteVery Helpful from one about to sit the ISTQB foundation level exam.
ReplyDeleteThank you for simple and great help
ReplyDeleteTHANKS....
ReplyDeleteThank you, it helped me understand in easy way.
ReplyDeleteany other example?
ReplyDeleteThank you so much for simplifying this! It is great help for the one who is not from IT background. Keep it up!
ReplyDeleteAccording to ISTQB Foundation book Branch coverage is not same as decision coverage because branch coverage including all conditional and unconditional ,but decision coverage only including conditional
ReplyDeletenot applicable for all..
ReplyDeleteGreat!!! Very helpful
ReplyDeleteThank you !!!
ReplyDeleteThanx a lot, Please provide me more examlpe of coverege. Revert back me on mohit3021@gmail.com
ReplyDeleteThanks for the explanation :)
ReplyDeleteVery good document to follow
ReplyDeleteThanks Anu and All of you
ReplyDeleteThank you, exactly an explanation I was looking for!
ReplyDeleteVery useful explanation with example.. thanks a lot
ReplyDeleteVery good and simplified manner to describe things...very good...keep it up....
ReplyDeleteThank you! This is of great help!
ReplyDeleteThanks a lot... I was totally confused. Now cleared
ReplyDeleteThanks a lot :)
ReplyDeleteThanks a bunch - sitting for this test in a couple of days and this was very helpful
ReplyDeleteThanks and how was your test?
DeleteExcellent Explanation.
ReplyDeleteThanks Anupam
DeleteIF A > B THEN
ReplyDeleteC = A � B
ELSE
C = A + B
ENDIF
Read D
IF C = D Then
Print �Error�
ENDIF
sir how to find branch coverage and decision coverage for this problem
Mahesh can you repost your example? I am getting �for operators
DeleteHi Mahesh !
DeleteI had the same question for ISTQB :D
the missing operator on line 2 is a "-" sign
SC=2 BC=2 PC=4
Thanks for the info Mohit.
Let me know if i am right !! :D
Thank You for the Helpful information in simple way
ReplyDeleteThanks Rani :-)
DeleteThe following flowchart has been tested with two test cases.
ReplyDeleteTC1: followed the path V X Z
TC2: followed the path VWZ
What level of coverage has been achieved?
o a) Statement coverage 100%; Decision coverage 100%
o b) Statement coverage 80%; Decision coverage 75%
o c) Statement coverage 75%; Decision coverage 75%
o d) Statement coverage 66%; Decision coverage 50%
Could not figure out how to calculate SC, BC, and PC after reading a bunch of materials. But this article helped to understand the process of calculation in the matter of minutes. Thanks a lot Mohit!
ReplyDeleteVery helpful for the students indeed.
ReplyDeleteRegards,
creately
thanks :-)
DeleteVery Helpful, thank you for posting this example. It was really easy to understand.
ReplyDeleteThank you Mohit,
ReplyDeleteI had difficulty understanding this Pseudo codes and they've given Me problems not knowing how to start my flow chart, is there somewhere I can find more problems to practice on? please send Me feedback on the my mail below:
dikoleisaac@live.com or dikoleisaac@gmail.com
Thank You Mohit.
ReplyDeleteYour explanation was great. i am preparing for istqb and i could not identify how to calculate statement and branch coverage.. it was very helpful plus in a simple and easy way.
Your explanation was great.
ReplyDeleteAwesome simply Awesome
ReplyDeleteThank you so much. It was very helpful.
ReplyDeleteThank you so much
ReplyDeleteThank you . Very helpful.
ReplyDelete//assume n1, n2, n3, count, sum and total are defined.
ReplyDeletepublic void someMethod(int n1, int num1, int num2, int num3) {
for(int i=0; i< n1; i++) {
if((n1 != num1)&&(n1 != num2)&&(n1 != num3))
count = 1;
else
count = 2;
if((n2 != num1)&&(n2 != num2)&&(n2 != num3))
sum = 3;
else
sum = 4;
if((n3 != num1)&&(n3 != num2)&&(n3 != num3))
total = 5;
else
total = 6;
}//end for(..)
}//end of method
Examine the sample code below then answer the following questions. How many tests are required for:
a. Statement coverage
b. Branch coverage.
c. Traversing every path through the algorithm.
i'm finding it's solution i'm new at this platform and i'm confused how to solve this it was the question in the paper