Condition and Modified Condition Coverage
What you'll learn: How to test complex boolean logic by ensuring each condition independently affects the outcome, crucial for safety-critical systems.
When you have compound boolean expressions like if (isValid && hasPermission || isAdmin), branch coverage only checks if the whole expression was true and false at least once. But what about the individual conditions? That's where condition coverage and Modified Condition/Decision Coverage (MC/DC) come in.
Condition Coverage
Condition coverage ensures every boolean sub-expression (each individual condition) evaluates to both true and false at least once across all test cases. In the example above, you'd need tests where isValid, hasPermission, and isAdmin each individually become both true and false.
However, condition coverage alone doesn't guarantee each condition actually matters to the outcome.
Modified Condition/Decision Coverage (MC/DC)
MC/DC goes further by requiring that each condition independently affects the decision's outcome. Think of it like testing whether each ingredient in a recipe actually changes the taste — not just whether you've used each ingredient at some point.
For each condition, MC/DC demands test pairs where:
- Only that one condition changes
- Everything else stays the same
- The overall decision flips
This is critical in safety-critical systems (aviation, medical devices, automotive) where regulators require proof that every logic condition matters and is properly tested. MC/DC catches subtle bugs where conditions might be incorrectly combined or redundant.
Key Takeaway: Condition coverage tests each boolean sub-expression for both outcomes; MC/DC ensures each condition independently influences the decision, providing thorough logic testing essential for safety-critical code.