~/qa-guides

~/qa-guides/mcdc-testing

>_ MC/DC Testing: Independence Pairs and Coverage Examples

Four reminder tests show how to isolate each condition in a decision. Read the execution traces, identify a missing pair, and work out what happens when one condition appears twice.

MC/DC testingStructural testingTest designCode coverage

Published

Short answer

Modified Condition/Decision Coverage (MC/DC) is a structural testing criterion that asks whether each condition in a decision has independently affected its outcome. Two executions form an independence pair when they demonstrate that effect. For unique-cause MC/DC, the target condition changes, the decision changes, and the other conditions retain their values.

Consider an app that shows a reminder when reminders are enabled and at least one task is overdue or due today. Four tests can isolate all three conditions. If the suite omits the due-today test, it can still show and hide the reminder correctly in every run while leaving that condition's effect untested.

What counts toward MC/DC coverage?

A decision is the whole expression that produces a Boolean result. A condition is one of its elementary Boolean parts. In temperature > limit AND fanAvailable, the comparison produces one condition and the availability flag supplies another. The values on the two sides of > are inputs to the comparison. They do not each earn a place in the condition count.

Three questions arise when reviewing a compound decision. Did it produce both outcomes? Did each condition evaluate to both true and false? For each condition, can you identify two executions where its change explains a change in the decision? The last question requires comparing executions. A list of tests with green checkmarks cannot answer it by itself.

For the percentages below, count the condition occurrences in one named decision that have at least one qualifying pair, then divide by the number of condition occurrences in that decision. An occurrence earns credit once even if several pairs qualify. The full MC/DC criterion also calls for exercising entry and exit points and obtaining both outcomes for every decision and every condition. See NASA's practical tutorial on modified condition/decision coverage.

MC/DC is particularly useful when reviewing a change to a compound rule. Adding an override, for instance, creates a new condition that may be hidden by a frequently true operand. Existing end-to-end tests are a good place to look for usable pairs if you can trace them to that decision. For a first look at how tests map to branches and statements, see the guide to black-box and white-box testing.

Build four test cases for a reminder

The requirement is to show one reminder if reminders are enabled and there is at least one unfinished task that is overdue or due today. In every other case the reminder must be hidden. The decision under review is A AND (B OR C).

  • A means reminders are enabled for the account.
  • B means the account has at least one overdue unfinished task.
  • C means the account has at least one unfinished task due today.

Freeze the account's local date at March 12. Give it an unfinished task due March 13 in every case so that an empty dashboard cannot explain a hidden reminder. A March 11 task sets B and a March 12 task sets C. A single task belongs to one date class, but two tasks can make both conditions true. Changing the reminder preference leaves the tasks in place.

Use a fresh copy of the account fixture for each row. Set the preference, load the due dates, and open the dashboard. Wait until the seeded tasks appear before checking whether the reminder is shown. Otherwise a loading error could satisfy an assertion that the banner is hidden. If collecting structural coverage, also record the evaluation of the named decision for that account.

TestA enabledB overdueC due todayExpected reminder
T1100Hidden
T2110Shown
T3101Shown
T4010Hidden

Here 1 means true and 0 means false. T2 and T4 deliberately contain the same overdue task. Turning reminders off on an account with only future tasks would also produce a hidden reminder, but turning them back on for that account would still leave the reminder hidden. That fixture cannot isolate the preference.

Find the independence pairs

Work outward from the condition you want to demonstrate. For B to affect the result of B OR C, choose C = 0. To let that result reach the decision, choose A = 1. You now have the entire setup for a pair before choosing either due date. The same reasoning yields a pair for each remaining condition.

TargetPairValues held fixedObserved change if the runs match the rule
AT4 and T2B = 1, C = 0Enabling reminders changes Hidden to Shown
BT1 and T2A = 1, C = 0Adding an overdue task changes Hidden to Shown
CT1 and T3A = 1, B = 0Adding a task due today changes Hidden to Shown

T2 supplies the enabled side of the A pair and the overdue side of the B pair. T1 is the shared starting point for both task conditions. Reusing an execution this way is legitimate because each comparison still varies just its own target.

Four tests are sufficient and necessary for unique-cause coverage of this expression with these inputs. The only way to isolate B uses 100 and 110, written in A, B, C order. Isolating C requires 100 and 101. Those three assignments all have reminders enabled, so at least one more assignment must turn them off. T4 supplies it. Another valid suite could switch the preference off on the due-today account, using 001 in place of T4 and pairing it with T3.

Read an incomplete coverage report

Suppose T1, T2, and T4 ran on the same build. Their traces confirm the decision outcomes shown above and their UI assertions passed. The decision produced both true and false. The test log also contains an overdue account with the preference both on and off. Which input would you request from the person running the next test?

The existing A pair is T4/T2 and the B pair is T1/T2. Every account in this run has C = 0. Two of three condition occurrences have a pair, giving 2 / 3 coverage for this decision. Add a task due March 12 to a copy of T1, keep its future task and enabled preference, and run T3. If it reaches the decision with the expected trace, T1/T3 supplies the third pair and coverage becomes 3 / 3.

Two tempting additions spend a run without filling that gap. An account with both kinds of tasks and reminders enabled differs from T2 in C alone, yet the overdue task already makes the reminder visible. An account with a due-today task and reminders disabled gives C a true input value, yet the disabled preference fixes the decision at false. For the missing pair, choose a context in which changing C can reach the result.

Keep the coverage observation and the test verdict

Imagine that T3's trace shows a true decision, but the UI hides the banner because a later rendering step drops it. T1/T3 can still demonstrate the effect of C at this decision. Record the observed pair and a failing UI assertion for T3. Recording only the coverage percentage would lose the defect the user actually sees.

The reverse case matters, too. If a cached dashboard already shows a reminder and T3 never invokes the decision, the UI assertion can pass. A planned pair with T1 gives you no execution evidence for that run. Capture the decision location, build, fixture IDs and corresponding evaluations so another reviewer can distinguish these two cases.

Read a short-circuit trace beside the inputs

Suppose the reminder function evaluates A && (B || C) from left to right. It can return false as soon as it reads a false A. With A true, it can return true as soon as it reads a true B. Assume the three reads have no side effects and their values stay fixed during one evaluation.

The table shows the traces you would expect from that implementation. The input column gives the three facts established by the fixture. The next three columns show what the decision actually reads. A skip means execution already had enough information to return.

TestInput ABCRead ARead BRead CDecision
T11001000
T211011skip1
T31011011
T40100skipskip0

Consider T4. The account contains an overdue task, which explains the 1 in the middle of its input. The program never asks about overdue tasks in this execution. Substituting 0 for the skipped read would make it appear that the program checked the task list and found nothing overdue. Substituting 1 would invent an observation that only the fixture supplies.

In the B pair, T1 reads B as 0 and T2 reads it as 1. The decision changes with it. The fixture holds C at 0 in both cases. Only T1 reads it. A reviewer can therefore reconstruct the unique-cause argument from the complete inputs and describe the runtime observations separately. If all you have is the trace, leave the skipped slot as recorded. For an example of how a tool uses executed test vectors and represents conditions made unevaluable by short-circuiting, see Clang's source-based code coverage documentation.

When every condition has taken both values

Suppose another suite uses 000, 100, 111 and 101. The first input reads a false A. The other three read a true A. Among those three, B is read as both false and true, and C is read as false in 100 and true in 101. Even with short-circuiting, every condition has really been evaluated both ways. The decision has also returned both values.

Now look for unique-cause pairs in those same four inputs. The only disabled account is 000. Its only partner differing in A alone is 100, and both hide the reminder. To isolate B, this suite would need 110 alongside 100. Its only qualifying pair is 100 with 101 for C. A report of both decision outcomes and both values of every condition can therefore coexist with just one of three unique-cause pairs. The test count is even the same as in the complete suite.

When the same condition occurs twice

A refactor spells the rule as (A AND B) OR (A AND C). Both forms give the same answer for every combination of the three stable inputs. The first form contains three condition occurrences. The expanded source contains four. Label them, in source order, A1, B, A2 and C. The two reads of the same preference are strongly coupled here. In every feasible assignment, A1 = A2.

Under a strict unique-cause rule for each occurrence, a pair for A1 would have to flip the preference at its first occurrence while keeping its second occurrence fixed. No account can supply those values. The same issue applies to A2. Giving the two reads separate controls in a test double would change the behavior under test. With this expression and stable preference, report the coupling when explaining the unavailable pairs.

Use masking to isolate the repeated preference

Masking MC/DC allows another occurrence to change in a pair when you can show that its change cannot affect the decision in that comparison. For the expanded rule, choose task data that makes a whole arm of the OR false at both ends. This lets you change the shared preference and identify which occurrence accounts for the decision change.

Add T5, an account with reminders disabled and just the future and due-today tasks. Its input is 001 and its expected reminder is Hidden. The following pairs use the same five physical fixtures throughout. A1 and A2 always receive the same preference value within a fixture.

Target occurrencePairInput ABCReason the target determines the change
A1T4 and T2010 to 110C = 0 forces the entire right arm false
BT1 and T2100 to 110Both A reads stay true and C stays false
A2T5 and T3001 to 101B = 0 forces the entire left arm false
CT1 and T3100 to 101Both A reads stay true and B stays false

In T5/T3, both occurrences of A change from 0 to 1. The left arm reads logically as A1 AND 0, which is false for either preference. The right arm reads as A2 AND 1, so the decision follows A2. T4/T2 applies the argument in the other direction. Its due-today condition is false, leaving the overdue arm to determine the result. These are proofs about the supplied Boolean values. An execution with short-circuiting may skip some of the reads used in that reasoning.

A change of result alone would give weaker evidence. Imagine switching reminders on for an account that has both an overdue task and a due-today task, moving from 011 to 111. At the enabled end, either arm can keep the result true even if the other arm goes false. You cannot single out either read of the preference as the cause using the argument that worked for T5/T3.

Report the criterion with the count

If the five runs yield the stated outcomes, the expanded expression has qualifying masking pairs for four of four occurrences. Under strict unique-cause analysis of the same assignments, B and C each have a pair, giving two of four. The two open occurrences are inseparable under the stated input constraint. Running more combinations from the same input domain cannot change that constraint.

Write the expression and variant next to the result, for example, (A AND B) OR (A AND C), masking MC/DC, 4 / 4, with the pair IDs in the table. The earlier 3 / 3 refers to a different source expression. For a tool-generated report, check which decision and occurrences the tool presents before transferring either count.

A test worth keeping after all three pairs are covered

Return to the original expression. The requirement says an overdue task or a task due today triggers a reminder. A customer can have one of each. Every enabled account in T1 through T3 has at most one qualifying task. What would those four tests tell you if someone implemented the rule as "exactly one of the two conditions is true"?

An exclusive OR gives the expected answer in all four cases. With T1 neither condition is true, with T2 and T3 exactly one is true, and T4 has reminders disabled. The suite that demonstrated all three pairs for the intended source would let this change pass its four product assertions. The coverage of the changed source would be a separate measurement.

Add a case with reminders enabled, the March 11 task, and the March 12 task. For input 111, inclusive OR predicts Shown and exclusive OR predicts Hidden. Assert that exactly one reminder appears even though two tasks qualify. This test distinguishes two plausible implementations and checks the user's experience when tasks overlap. If you deliberately introduce a change like exclusive OR, you can assess its effect on the tests with the guide to surviving and equivalent mutants.

There is a second reason to keep the dates visible in the fixture. A classifier that mistakenly puts today's task in the overdue pile could still show the expected banner in T3. The diagnostic clue would be the input actually reaching the decision, 110 in place of the intended 101. Preserve the failing date example for the classifier and rerun the intended independence pair once the fixture reaches the decision with the right facts.

FAQ

Yes. If a requirements table already lists all eight feasible A, B, C combinations, look for columns that supply the needed pairs and map each selected column to an execution of the implemented decision. T1 through T4 exercise four of those eight columns and supply all three unique-cause pairs for the factored expression. A team aiming to exercise every feasible column still has four columns to execute. The decision table testing guide explains how to choose the denominator for full and minimized tables.

Two identifiable evaluations can come from one parameterized test or even from one user journey. For example, open the overdue account with reminders disabled, enable them, and let the dashboard recompute. Save the before and after evaluations and check both displayed states. A report containing only the final state loses the evidence for the disabled half of the pair.

For a whole-day comparison such as daysPastDue >= 7, choose 6 and 7 while fixing the other conditions so this comparison determines the result. The pair both flips the condition and distinguishes >= 7 from > 7. Testing 2 and 20 would also flip the intended condition, but both comparisons agree at those values. The precise threshold gives the pair a second purpose.

Retain fixtures and requirement assertions that still describe the intended behavior. Then identify each condition occurrence in the revised source, rerun the tests, and rebuild the pair mapping for that version. The reminder example can reuse T1 through T4 after the rewrite. T5 becomes useful specifically because the revised expression contains a second read of the preference.

The equivalence used in the refactor assumes stable, side-effect-free reads. Suppose the first preference read is true, the overdue flag is false, and the due-today flag is true. The factored form returns true. If a second preference read now returns false, the expanded form returns false. Establish whether the requirement uses a snapshot or fresh readings before designing pairs. When fresh readings are intentional, the order and outcome of each read become part of the test data.

Ready to turn this guide into a working QA project with statuses, comments, and CSV export?