Decision coverage (or branch coverage) testing is a form of white box testing.
Within the scope of decision coverage testing, all possible branches from each decision point are executed at least once. This implies that all the edges of the control flow graph are traversed.
Decision coverage can be calculated using the formula below:
A decision point is a point in the control flow graph where the control of the program diverges. Common examples include do-while
statements, if
statements, and case
statements.
These statements are also referred to as control flow statements.
Consider the following pseudocode:
Example (int x)
{
if (x < 10)
print("x < 10")
else
print("x >= 10")
}
The control flow graph for the above code snippet is depicted below:
For the above graph, to cover all the edges, we will need at least two test cases.
First, we execute the above code with a test value that is less than 10. Let’s run it for x = 7
.
For the case x = 7
, the true
branch of the decision point is taken. The regions of the graph that are traversed are highlighted in green colour.
The decision coverage is:
Now, we will execute the code with a test value that is greater than or equal to 10. Let’s run it for x = 12
.
For the case x = 12
, the false
branch of the decision point is taken. The regions of the graph that are traversed are highlighted in red colour.
The decision coverage is:
Now that we have attained a total decision coverage of 100% (50 + 50), let’s summarize the result in the form of a table.
Test Case | Value of X | Expected Output | Observed Output | Decision Coverage | Result |
1 | 7 | "x < 10" | "x < 10" | 50% | Pass |
2 | 12 | "x >= 10" | "x >= 10" | 50% | Pass |
Free Resources