Decision Testing and Coverage

Profile picture for user devraj

Decision testing is a form of white-box testing, which involves the systematic examination of decisions within software code to validate their expected outcomes. The code is exercised and tested through this technique to ensure it executes according to its intended behavior based on decision outcomes.

The primary objective of decision testing is to verify that all possible branches deriving from each decision point are executed at least once, ensuring that all reachable code is exercised.

Decision testing, in contrast to Modified Condition/Decision Coverage and Multiple Condition techniques, considers the entire decision and evaluates the TRUE and FALSE outcomes in separate test cases. It's important to note that a single test case may exercise several decision outcomes.

Table of Contents

Decision Points

A decision point is a juncture in the program's control flow graph where program control diverges. Test cases designed for decision testing follow control flows from these decision points. For example, 

  • For an IF statement, two test cases are required, one for the true outcome and another for the false outcome. 
  • In contrast, for a CASE statement, test cases should be designed to cover all possible outcomes, including the default outcome
  • Similarly, for a loop statement, two control flows must be tested, one for the true outcome of the loop condition and another for the false outcome.

Branch Coverage Vs. Decision Coverage

Branch testing is frequently used interchangeably with decision testing since it is possible to achieve complete coverage of all decision outcomes and branches with the same set of tests. Moreover, for almost all programs, achieving 100% coverage of decisions and branches is equivalent.

Test Case Coverage

Typically expressed as a percentage, coverage is calculated as the number of decision outcomes executed by the tests divided by the total number of decision outcomes in the test object.

Decision Coverage Testing Example

Let us consider the same example we discussed for Statement Coverage. To evaluate the Decision coverage of a function that determines the greater of two numbers, two test cases are executed. 

Decision Testing and Coverage
  • In the first test case, if X=20 and Y=10, the true branch is executed, resulting in a coverage of 50% (1 decision executed out of 2).
  • Similarly, in the second test case, if X=10 and Y=20, the false branch is executed, also resulting in a coverage of 50%. Since both test cases execute all the decisions, the overall coverage of the function is 100%

The Value of Decision Testing

Attaining 100% decision coverage implies the execution of all decision outcomes, including testing the true and false results, even when no explicit false statement exists (such as in an IF statement lacking an ELSE clause).

Decision coverage uncovers defects in code where other tests have not considered both true and false outcomes. Importantly, achieving 100% decision coverage ensures 100% statement coverage, though the reverse is not always true.

Benefits of Decision Coverage

Decision coverage confers several benefits. 

  • By testing every possible branch from each decision point at least once, it guarantees that no branch will lead to any abnormality in the program's operation. 
  • Additionally, decision coverage can address problems that may arise with statement coverage testing.

Limitations of Decision Coverage

Decision coverage also has limitations. 

  • Testing at the decision level may require more test cases than testing only at the statement level, which could pose a challenge when time is a constraint.
  • Additionally, decision testing overlooks the specifics of how decisions with multiple conditions are made, potentially missing defects caused by combinations of these conditions. 
  • Furthermore, this metric fails to account for branches within Boolean expressions that arise from short-circuit operators.