# How do we calculate Statement coverage, Branch coverage, Path coverage and Condition coverage?

• I am preparing for a testing certification. These types of questions are asked frequently.

``````Example 1:
IF P+Q > 100 THEN
Print “Large”
ENDIF
If P > 50 THEN
Print “P Large”
ENDIF

Example 2:
I F X>Y THEN Z = 0
ENDIF

Example 3:
3 Z =X + 2*Y
4 IF Z> 50 THEN
5 PRINT large Z
6 ENDIF
`````` What are Nodes and Edges in the flowchart?

``````Statement Coverage: 1A-2C-3D-E-4G-5H = 1
Branch Coverage: 1A-2C-3D-E-4G-5H , 1A-2B-E-4F = 2
Path Coverage: 4
1A-2B-E-4F
1A-2B-E-4G-5H
1A-2C-3D-E-4G-5H
1A-2C-3D-E-4F
``````

In these example, how do we identify that which is a statement, branch and condition? How do we measure coverage? Please give detailed explanations of ALL 3 examples.

• How the answers are calculated

• Statements : Simply, these are what you have in the boxes and diamond shapes.
• You can cover all the statements in the flowchart by writing 1 Test Case that follows the following route
• 1A-2C-3D-E-4G-5H.
• Therefore, the Statement Coverage is 1

• Branches/Decisions : Decisions that you can take in the process flow diagram (For example, if you consider the statement 2, there are two branches to it)
• You can cover all the branches in the flowchart by writing 2 Test Cases that follow the following two routes
• 1A-2C-3D-E-4G-5H
• 1A-2B-E-4F
• Therefore, the Branch Coverage is 2

• Paths : paths that you can take to travel in the flow chart from the start to the end.

• You can cover all the paths in the flowchart by writing 4 Test Cases that follow the following four routes
• 1A-2B-E-4F
• 1A-2B-E-4G-5H
• 1A-2C-3D-E-4G-5H
• 1A-2C-3D-E-4F
• Therefore, the Path Coverage is 4

Coverage

Coverage can be calculated for all the three techniques mentioned above.

• Statement coverage
• Let us say your test case covers the following route - 1A -> 2B -> E -> 4F
• There are total of 5 Statements in your flowchart
• You cover only 3 Statements
• Calculate the Statement Coverage - (3/5)*100
• Your Test Case, therefore, has 60% of Statement Coverage

• Branch coverage
• Let us say your test case covers the following route - 1A -> 2B -> E -> 4F
• There are total of 4 Branches/Decision in your flowchart (2 decisions for Statement no 2 and 2 decisions for Statement no 4)
• You cover only 2 Branches/Decisions
• Calculate the Branch/Decision Coverage - (2/4)*100
• Your Test Case, therefore, has 50% of Statement Coverage

• Path coverage
• Let us say your test case covers the following route - 1A -> 2B -> E -> 4F
• There are total of 4 Paths in your flowchart
• You cover only 1 Path
• Calculate the Path Coverage - (1/4)*100
• Your Test Case, therefore, has 25% of Path Coverage

2

2

2

2

2

2

2

2