The idea: a decision is made of conditions
Branch coverage asks each if to go both ways. But one if can hold several
tests joined by && and ||. The whole boolean expression is the
decision. Each part with no && or || inside is a
condition. The page tests this method:
boolean mayDrive(int age, boolean licence, boolean instructor) {
if (age >= 18 && (licence || instructor))
return true;
return false;
}
Three conditions can be true or false, so there are 2 × 2 × 2 = 8 rows in the truth table. The middle panel shows them. Age 20 makes A true and age 16 makes it false, so every row is one test. Press Add Test to add a row to the suite.
Decision coverage and condition coverage
Decision coverage asks for D to be true once and false once. This is branch
coverage for one if. Condition coverage asks for every condition to
be true once and false once. They sound alike, but neither one gives the other.
| Suite (rows) | Decision | Condition | What is missed |
|---|---|---|---|
| 2 (TTF), 6 (FTF) | 2/2 = 100% | 4/6 = 67% | B is never false, C is never true |
| 4 (TFF), 5 (FTT) | 1/2 = 50% | 6/6 = 100% | D is never true |
In the second suite each condition flips between the two tests, yet D is false both times. The
method never returns true, and a bug in that return would not be seen.
Demo 1: decision coverage, conditions missed and Demo 2: condition coverage, decision
missed.
Condition/decision coverage
The fix is to ask for both: condition/decision coverage (8 items here). Two tests are enough: row 1 (all true) and row 8 (all false). Demo 3: condition/decision with 2 tests scores 8/8.
But look at what these two tests prove. If the code had only age >= 18, both tests
would still pass: row 1 gives true and row 8 gives false either way. The suite never shows that
licence or instructor matters. MC/DC is 0/3.
MC/DC: each condition must matter on its own
Modified condition/decision coverage (MC/DC) keeps condition/decision coverage and adds one rule: for every condition there must be two tests that differ only in that condition and give different values of D. Such two tests are an independence pair. They show that the condition alone can change the outcome.
To find the pairs, take each condition in turn. Look for two rows where only that condition changes, then check whether D changes too. Demo 4: find the independence pairs fills the three pair columns of the table.
| Condition | Pairs (rows) | Why the other rows fail |
|---|---|---|
A: age >= 18 | 1 & 5, 2 & 6, 3 & 7 | rows 4 & 8: B and C are both false, so D is F either way |
B: licence | 2 & 4 | C = T keeps D true (1 & 3); A = F keeps D false (5 to 8) |
C: instructor | 3 & 4 | B = T keeps D true (1 & 2); A = F keeps D false (5 to 8) |
When one condition holds D in place, it masks the others. In an || a
true part masks the rest; in an && a false part does.
N + 1 tests instead of 2^N
Now pick a suite that contains one pair for every condition. B has only the pair 2 & 4 and C only 3 & 4, so rows 2, 3 and 4 are needed. For A, add row 6 (pair 2 & 6) or row 7 (pair 3 & 7). That is 4 tests: N + 1 for N = 3 conditions. Demo 5: MC/DC with N + 1 = 4 tests builds it and every criterion reaches 100%.
Four tests are not always MC/DC. Rows 1, 2, 4 and 5 give full condition/decision coverage and pairs for A (1 & 5) and B (2 & 4), but C has no pair: Demo 6: 4 tests, still not MC/DC ends at 2/3.
For a decision with N conditions, MC/DC needs at least N + 1 tests and usually not many more (at most 2N). Testing every row needs 2^N tests:
| Conditions N | All rows 2^N | MC/DC at least N + 1 |
|---|---|---|
| 3 | 8 | 4 |
| 5 | 32 | 6 |
| 10 | 1,024 | 11 |
| 20 | 1,048,576 | 21 |
Where MC/DC is required
MC/DC came from avionics. DO-178C requires it for level A airborne software, where a failure could
bring down the plane. ISO 26262 recommends it for the highest car safety level (ASIL D). In
everyday projects teams usually stop at branch coverage. Some compilers can now measure it:
GCC 14 has -fcondition-coverage and Clang 18 has -fcoverage-mcdc.
Short-circuit evaluation. Java stops evaluating && as soon as A
is false, so in rows 5 to 8 B and C never run. The page uses the truth-table view, where every
condition has a value. The suite rows 2, 3, 4, 6 still works with short-circuit: in row 6 the
values of B and C do not matter, and the A pair 2 & 6 only needs A to change.
See also Control-Flow Coverage for statement, branch and path coverage on a whole method, Equivalence Partitioning and Boundary Value Analysis for choosing input values from the specification, and Truth Tables and Sets for building a truth table.
See also Mutation Testing, which checks whether the tests would notice a small change to the code, not only whether they run it.
What the page leaves out
Masking MC/DC (pairs where the other conditions may change if they are masked) and the coupled
conditions that need it, multiple condition coverage as a named criterion (it is the full 8-row
table), decisions outside an if (such as boolean ok = a && b;),
object-code coverage, and how tools instrument the code are left out. Mutation testing is a
different way to judge a test suite and is not covered here.