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.
What is statement coverage and branch 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.
Statement coverage does not ensure coverage of all functionality.
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.
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.
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.
IF P+Q > 100 THEN
If P > 50 THEN
Print “P Large”
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 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-
So path coverage is 4.
Thus for the above example SC=1, BC=2 and PC=4.
- 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
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
ISTQB Guru provides 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.
Use the discount code ISTQBGuru to get 20% off when you download directly.