software-engineering testing

Definition

Condition/Decision Coverage

Condition/Decision Coverage (or C+B) is a strong white-box testing metric that combines the requirements of both condition coverage and branch coverage.

To satisfy this metric, a test suite must ensure:

  1. Every atomic condition in a decision has taken all possible outcomes (True and False).
  2. Every decision (branch) has taken all possible outcomes (True and False).

Concept

Since condition coverage and branch coverage are independent (one does not imply the other), C+B Coverage serves as a union of both metrics to close the testing gaps.

  • Gap Closed: It prevents the scenario where atomic conditions are tested (condition coverage) but the code only ever takes the “True” path (0% branch coverage).
  • Limitation: It still does not test how the combinations of conditions affect the outcome (e.g., it doesn’t require testing specifically when ). For that, DC is used.

Example

Consider the following code snippet and its CFG:

if (A || B) {   // BB_1 (Decision)
    // True     // BB_2
} else {
    // False    // BB_3
}
graph TD
    Entry((Entry)) --> Dec{"BB<sub>1</sub>:  b<sub>1</sub> = A || B"}
    Dec -- "b<sub>1</sub>" --> TrueBlock["BB<sub>2</sub>:  True Branch"]
    Dec -- "&not; b<sub>1</sub>" --> FalseBlock["BB<sub>3</sub>:  False Branch"]

Test Suite:

  1. T1: Result: True ()
  2. T2: Result: True ()
  3. T3: Result: False ()

Analysis:

  • Conditions:
    • : True (T1), False (T2/T3). Covered.
    • : True (T2), False (T1/T3). Covered.
  • Branches:
    • Result True (T1/T2). Covered.
    • Result False (T3). Covered.
  • Conclusion: 100% C+B Coverage.

Strategy

  1. Denominator (Total Targets):
  1. Numerator (Executed Targets): Run the trace (minding short-circuits).
  1. Result:

Example: The Short-Circuit Gap

Code: if (A || B)

  • Denominator: 2 Decisions + 4 Conditions = 6.

Test Case: A=True

  1. Conditions: A is True. B is skipped. (Hits: 1)
  2. Branches: Decision is True. (Hits: 1)
  3. Result: .