Junior · White Box Technique

Decision Coverage

Test the "Yes" and the "No." Decision Coverage (also called Branch Coverage) ensures you've tested every possible outcome of every decision point in the code.

Junior ISTQB CTFL 4.3.2 — K2 Understand ~12 min read + exercise

1 The Hook — The "Half-Tested" Logic

Imagine a smart-home system that turns the heater ON if the temperature is below 15°C. You test it by putting the sensor in the freezer. The heater turns ON. 100% Statement Coverage! You hit the line that turns the heater on.

But what if you never test it when the temperature is 25°C? You might not realise that the developer forgot to write the code that turns the heater OFF. Statement Coverage proves you can turn it ON; Decision Coverage proves you can turn it OFF too.

2 The Rule — True + False

Coverage % = (Number of Decision Outcomes Executed ÷ Total Number of Decision Outcomes) × 100

Every if statement has two outcomes (True/False). Every switch case is an outcome. To get 100% Decision Coverage, you must hit both sides of every decision point.

3 The Analogy — The Interislander Ferry

Analogy

The Truck vs. Car Lane.

When you board the Interislander ferry in Wellington, there's a sign: "Trucks Left, Cars Right." Decision Coverage is like making sure at least one Truck goes left AND at least one Car goes right. If you only test with 100 cars, you've only tested the "Right" branch. You have no idea if the "Truck" lane is blocked by a fallen cone or leads into the ocean. You must test both branches to prove the system works for everyone.

4 Watch Me Do It — GST Registration

Scenario: You're testing code that checks if a NZ business should pay GST.

JS Code: calculateTax(revenue)
function calculateTax(revenue) {
  if (revenue > 60000) {      // Decision 1
    return revenue * 0.15;    // Branch A (True)
  }
  return 0;                   // Branch B (False)
}
  • Test Case 1: revenue=100,000.
    Outcome: True. Hits Branch A. Decision Coverage: 1/2 (50%).
  • Test Case 2: revenue=10,000.
    Outcome: False. Hits Branch B. Decision Coverage: 1/2 (50%).
  • Combined: Running both tests ensures 100% Decision Coverage.

5 Decision Tool — Decision vs. Statement

Why bother with Decision Coverage if Statement Coverage is easier?

📓 Statement Coverage

  • Hits every line.
  • Can miss the "Else" path if it's empty.
  • Weakest white-box metric.

🛡 Decision Coverage

  • Hits every branch.
  • Ensures "No" paths work correctly.
  • Always achieves 100% Statement Coverage.

6 Common Mistakes

🚫 Forgetting the "Hidden" Else

I used to think: If there's no else block, there's only one branch.
Actually: Even if there is no else, the code still has a "False" path (skipping the if). You must test skipping the block to get 100% Decision Coverage.

🚫 Only testing the "Happy Path"

I used to think: I'll just test the path that works.
Actually: Decision coverage is specifically designed to force you into the "Sad Paths" — error handling, validation failures, and edge cases.

7 Now You Try — Pick the Suite

🎯 Interactive Exercise

Function: if (age >= 18) { grantAccess(); }

Which test suite achieves 100% Decision Coverage?

Hint: You need one value that is >= 18 (True) and one that is < 18 (False).

8 Self-Check

Q1. If you have 100% Decision Coverage, do you also have 100% Statement Coverage?

Yes. If you've hit every possible branch, you've by definition hit every line of code inside those branches. This is why Decision Coverage is considered "stronger."

Q2. How many test cases are needed for a single 'if' statement to get 100% Decision Coverage?

Two. One to satisfy the condition (True) and one to fail the condition (False).

9 Interview Prep

"Is 100% Decision Coverage enough to guarantee no bugs?"

Answer: "No. While Decision Coverage ensures we've tested both sides of every 'If', it doesn't account for Multiple Conditions inside that if. For example, if (A and B) could be tested with A=True, B=True (True) and A=False, B=True (False), but we've never tested what happens when B=False. For that, we need Condition or MC/DC coverage."