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;
}
The line if (age >= 18 && (licence || instructor)) with three conditions marked: A is age >= 18, B is licence, C is instructor. The whole expression is the decision D. Below, four criteria: decision coverage needs D true and false (2 items), condition coverage needs A, B, C each true and false (6 items), condition/decision needs both (8 items), MC/DC needs each condition shown to flip D on its own (3 pairs)
One decision D with three conditions A, B, C, and what each coverage criterion asks for.

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)DecisionConditionWhat 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.

Left: rows 2 and 4 differ only in B (T then F) and D goes from T to F, so they are a pair for B. Right: rows 1 and 3 also differ only in B, but D stays T because C is true, so they are not a pair for B
Rows 2 and 4 are a pair for B; rows 1 and 3 are not, because C = T keeps D true.

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.

ConditionPairs (rows)Why the other rows fail
A: age >= 181 & 5, 2 & 6, 3 & 7rows 4 & 8: B and C are both false, so D is F either way
B: licence2 & 4C = T keeps D true (1 & 3); A = F keeps D false (5 to 8)
C: instructor3 & 4B = 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 NAll rows 2^NMC/DC at least N + 1
384
5326
101,02411
201,048,57621

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.

On the mind map

Open the Software Design mind mapSoftware DesignPrinciples: keep each change localPrinciplesDesign patterns: named fixes for common designsDesign patternsArchitecture: the shape of a whole appArchitectureEnterprise app patterns: logic, SQL, locks, money (PoEAA)Enterprise app patternsGit storage: content named by its hashGit storageGit branches & merging: pointers to commits, then mergeGit branches & mergingTesting: check code in isolationTestingSOLIDSOLIDfive rules so one change hits one classInheritance vs compositionInheritance vs compositionis-a locks the tree; has-a mixes partsVirtual calls, vtableVirtual calls, vtableobject → vptr → vtable slot → functionOverloading vs overridingOverloading vs overridingjavac: static types; JVM: receiver's classCoupling and cohesionCoupling and cohesionOne change should touch one moduleControl-flow coverageControl-flow coverage100% statements can still miss a bugBoundary Value TestingBoundary Value TestingBugs sit at class edges: test min−1 … max+1Condition Coverage and MC/DCEach condition flips D alone: N+1 testsMutation testingMutation testingCoverage runs code; mutants test the assertsOpen the Software Design mind mapSoftware Designkeep each change localPrinciplesSOLIDSOLIDfive rules so one change hits one classInheritance vs compositionInheritance vs compositionis-a locks the tree; has-a mixes partsVirtual calls, vtableVirtual calls, vtableobject → vptr → vtable slot → functionOverloading vs overridingOverloading vs overridingjavac: static types; JVM: receiver's classCoupling and cohesionCoupling and cohesionOne change should touch one moduleControl-flow coverageControl-flow coverage100% statements can still miss a bugBoundary Value TestingBoundary Value TestingBugs sit at class edges: test min−1 … max+1Condition Coverage and MC/DCEach condition flips D alone: N+1 testsMutation testingMutation testingCoverage runs code; mutants test the asserts
This page on the Software Design mind map · 38 pages in 7 branches · open it to see the whole map and test yourself in recall mode.