How to calculate Statement, Branch/Decision and Path Coverage for ISTQB Exam purpose. This may be applicable for both ISTQB Foundation Level and General Test Coverage concepts in Advanced Level exam. Follow the below given example to understand the concepts of while box testing coverage as described in the ISTQB Syllabus.
*** A recently published book on ISTQB has copied the exact content from this tutorial and plagiarized the content by copying word by word and the diagrams used here. We have sent legal notice to the author. If the author does not remove the content in the next edition of the book, we will expose the name of the author here. ***
What is statement coverage and branch coverage?
Statement Coverage:
A Statement is: An entity in a programming language, which is typically the smallest indivisible unit of execution. The objective of the statement coverage testing is to show that the executable statements within a program have been executed at least once. An executable statement can be described as a line of program source code that will carry out some type of action.
According to ISTQB Glossary, a Statement coverage is the percentage of executable statements that have been exercised by a test suite. Therefore, to achieve 100% Statement coverage we have to make sure that every statement in the code is executed at least once. So, we will need test case(s) executed in such a way that every statement of the code is executed at least once during the test execution.
To calculate statement coverage, you need to determine the total number of statements in the code and the number of statements that have been executed during the testing. Statement coverage is then calculated by dividing the number of executed statements by the total number of statements and multiplying by 100 to get a percentage.
Statement coverage = (Executed statements / Total statements) * 100
Statement coverage does not ensure coverage of all functionalities.
Branch/Decision Coverage:
A Decision is: A program point at which the control flow has two or more alternative routes. A node with two or more links to separate branches. The objective of decision coverage testing is to show all the decisions within a component have been executed at least once. A decision can be described as a line of source code that asks a question.
According to ISTQB Glossary, a Branch coverage is the percentage of branches that have been exercised by a test suite. 100% branch coverage implies both 100% decision coverage and 100% statement coverage. Whereas a Decision coverage is he percentage of decision outcomes that have been exercised by a test suite. 100% decision coverage implies both 100% branch coverage and 100% statement coverage.
100% decision coverage implies both 100% branch coverage and 100% statement coverage.
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.
To calculate branch/decision coverage, you need to determine the total number of branches in the code and the number of branches that have been executed during the testing. Branch decision coverage is then calculated by dividing the number of executed branches by the total number of branches and multiplying by 100 to get a percentage.
Branch decision coverage = (Executed branches / Total branches) * 100
Both of these metrics (Statement Coverage and Brance/Decision Coverage) are important for ensuring that your test cases are thorough and that your code has been adequately tested. It’s important to note that achieving 100% coverage does not guarantee that your code is bug-free, but it does increase the likelihood that your code is working as intended.
Is branch coverage the same as decision coverage?
Branch coverage is closely related to decision coverage and at 100% coverage they give mostly the same results. Decision coverage measures the coverage of conditional branches; branch coverage measures the coverage of both conditional and unconditional branches.
Path Coverage:
The percentage of paths that have been exercised by a test suite. 100% path coverage implies 100% LCSAJ coverage. LCSAJ stands for Linear Code Sequence and Jump.
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.
A Linear Code Sequence And Jump, consists of the following three items (conventionally identified by line numbers in a source code listing) the start of the linear sequence of executable statements, the end of the linear sequence, and the target line to which control flow is transferred at the end of the linear sequence. LCSAJ coverage The percentage of LCSAJs of a component that have been exercised by a test suite. 100% LCSAJ coverage implies 100% decision coverage.
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.
Solution:
The flow chart is-
Statement Coverage (SC):
To calculate Statement Coverage, find out the shortest number of paths following which 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 will ensure 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
*LCSAJ = Linear Code Sequence and Jump.
In our self-study guide we have included more detailed steps and hundreds of questions on whitebox test design techniques. Our study materials are updated based on the latest ISTQB Syllabus 2018. You can also get our free dumps and mock tests here.
Note: Of the two white-box techniques (Statement Testing and Decision Testing), statement testing may provide less coverage than decision testing. Achieving 100% decision coverage guarantees 100% statement coverage (but not vice versa). ISTQB 2018 syllabus does not differentiate between decision coverage vs condition coverage.
Statement Coverage / Decision Coverage ISTQB Sample Questions
Q.No. 1 – Which of the following is NOT a valid use of decision coverage?
A. Checking that all decisions have been exercised in a single program
B. Checking that all decisions have been exercised in a business process
C. Checking that all decisions are based on a numeric value
D. Checking that at least 100% decision coverage has been achieved, as this guarantees 100% statement coverage
Correct Answer: C
Q.No. 2 – A program got 100% decision coverage in a test. Which of the following statements is then guaranteed to be true?
A. Every output equivalence class has been tested.
B. Every executable statement is covered.
C. The “dead” code has not been covered.
D. Every input equivalence class has been tested.
Correct Answer: B
Q.No. 3 – Consider the following pseudo-code
How many minimum test cases are required to cover 100% Statement Coverage and Decision Coverage?
A. 4 for Statement, 5 For Decision
B. 5 for Statement, 5 for Decision
C. 6 for Statement, 8 for Decision
D. 8 for Statement, 6 for Decision
Correct Answer: A
Solution to Question number 3:
To cover all the statements in the program, we have to execute minimum the following flows (So the minimum test cases required for statement coverage is 4).
- A-B-C
- A-B-D
- A-D-E-F
- A-D-G
For Decision coverage, the above 4 flows are needed to cover all the decision points. However, we can see that there is one missing branch H which is not mentioned in the given code snippet. So it is possible that the code might end up executing the flow A-D-E-H. So to achieve 100% decision coverage we will need minimum 5 test cases.
Q.No. 4 – The following statement refers to decision coverage:
“When the code contains only a single ‘if’ statement and no loops or CASE statements, any single test case we run will result in 50% decision coverage.”
Which of the following sentences is correct?
A. The sentence is true. Any single test case provides 100% statement coverage and therefore 50% decision coverage.
B. The sentence is true. Any single test case would cause the outcome of the “if” statement to be either true or false.
C. The sentence is false. A single test case can only guarantee 25% decision coverage in this case.
D. The sentence is false. The statement is too broad. It may be correct or not, depending on the tested software.
Correct Answer: B
Q.No. 5 – Which one of the following is the BEST description of statement coverage?
A. It is a metric which is used to calculate and measure the percentage of test cases that have been executed.
B. It is a metric, which is used to calculate and measure the percentage of statements in the source code which have been executed.
C. It is a metric, which is used to calculate and measure the number of statements in the source code which have been executed by test cases that are passed.
D. It is a metric that give a true/false confirmation if all statements are covered or not.
Correct Answer: B
Q.No. 6 – Which TWO of the following statements about the relationship between statement coverage and decision coverage are true?
Select two options
A. Decision coverage is stronger than statement coverage.
B. Statement coverage is stronger than decision coverage.
C. 100% statement coverage guarantees 100% decision coverage.
D. 100% decision coverage guarantees 100% statement coverage.
E. Decision coverage can never reach 100%.
Correct Answers: A and D
Q.No. 7 – Consider the following Pseudo code:
How many minimum test cases are required to cover 100% statement coverage and decision coverage?
A. 2 for Statement, 5 For Decision
B. 1 for Statement, 2 for Decision
C. 1 for Statement, 5 for Decision
D. 5 for Statement, 1 for Decision
Correct Answers: C
Solution: Draw a flow diagram like Q No 3 above and find the missing the branches in the pseudo code. Want Sure pass dumps for BCS, ITB, iSQI, ASTQB, GASQ exams, contact us.
ISTQB Guru provides 100% Sure Pass Self Study materials for ISTQB Foundation Level.
ISTQB Dumps, Exam tips, more tips on Statement coverage, decision coverage, path coverage can be found in our premium ISTQB study guide based on ISTQB 2018 Syllabus. You can download instantly.
100% Passing Rate ISTQB Dumps and Guide – A Complete Self Study Package – Click Here to Know more
Use the discount code 50OFF to get 50% off when you download directly.
usha says
It helps to know exact how to calculate statement, branch and path coverage
ISTQB Guru says
Thank you.
beck says
So amazing and clear explanation. thanks
ISTQB Guru says
Thank you. Glad that this article helped you.
Olga says
The best explanation and very quick response for my answer. Thank You
ISTQB Guru says
You are welcome. Glad that this article was helpful to you.
ISTQB Guru says
We have added new questions and added explanation to Q no 3.
zebu says
Can I get the solution of 3 question
ISTQB Guru says
Please chat with here. https://www.facebook.com/ISTQB.Guru/
We can guide you step by step.
sharmila says
best explaination. Thank you
ISTQB Guru says
Thank you.
harry says
can anyone explain Q.No. 3 with flow chart and how the ans comes as A?
Suganya says
Awesome explanation
Bhushan Patil says
Really Best explanation for this topic, thank you
ISTQB Guru says
Glad that it helped you.
Christa Glady says
Wow, awesome explanation
Pushpinder kaur says
Very well explained .. thx a lot
Rajinder Singh says
best explanation!!
ISTQB Guru says
Thank you.
susmita prusti says
really its very helpful.thank you so much…
Onkar says
Thanks a lot ,for short and simple
Mani says
What is the boundary value alalysis for picture resolution say 468×829
Sarah says
Really good and simple explanation! Thank you!
Swapna says
Good Explanation for the minute differences among them. This article will help many students preparing for istqb in particular.
neha says
very good explanation .. thanks
Ada says
Thank you. This is really helpful.
Amiirah says
Great. Very helpful
TC says
Thank you. This was very helpful.
Vivience Hoang says
Thank you so much
Usha says
Thank you 🙂 It’s so clear
Kalyan says
Thanks…
vindhya says
Thank you! Good explanation
SRINATH says
Good explanation!
Maryum says
Thank You 🙂
C Reddy says
Good one.
pjain says
good one
dipali says
good explanation
Suliko says
Thank you very much! Very good explanation!
Archana says
Best description! Was confused earlier but this helped a lot!
Jessica says
I had asked before why an specific premium question was BC = 3, but now I can understand the reason. Thank you so much, your material is very helpful.
Syed Imran says
good training material
Prabhu says
Good explanation..thank you
linh says
Thanks so much, it’s very clear and easy to understand
LearnerISTQB says
Good explanation…..
Nattinna says
Thanks a lot!!!
Sandy says
It’s the best description for SC, BC and PC coverage