What is decision coverage testing?

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:

Calutating decision coverage

Decision points

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.

Decision point in a control flow graph

Example

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:

Control flow graph

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.

Outcomes exercised 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:

Coverage=12100=50%Coverage = \frac{1}{2} * 100 = 50\%

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.

Outcome exercised 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:

Coverage=12100=50%Coverage = \frac{1}{2} * 100 = 50\%

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

Copyright ©2025 Educative, Inc. All rights reserved