Certainly! MC/DC stands for Modified Condition/Decision Coverage. It is a code coverage criterion used primarily in safety-critical software (like avionics, automotive, and medical devices) to ensure thorough testing of decision logic.
What is MC/DC?
MC/DC requires that:
- Each condition in a decision has been shown to independently affect the decision's outcome.
- Every entry and exit point in the program has been invoked.
- Every decision in the program has taken all possible outcomes at least once.
- Every condition in a decision has been shown to independently affect that decision's outcome.
Let's break it down:
- Decision: A Boolean expression (e.g.,
if (A && B))
- Condition: Each Boolean sub-expression (e.g.,
A, B)
MC/DC Coverage Criteria
For a decision with multiple conditions (e.g., if (A && B)), MC/DC requires that:
- Each condition is tested with both true and false values.
- For each condition, there must be at least one pair of test cases where:
- The condition changes value (from true to false or vice versa).
- All other conditions remain the same.
- The overall decision outcome changes as a result.
Example
Suppose you have this code:
if (A && B)
// do something
To achieve MC/DC, you need test cases that show:
- Changing A alone can change the outcome of the decision.
- Changing B alone can change the outcome of the decision.
Test Cases:
| Test | A | B | (A && B) |
|---|
| 1 | T | T | T |
| 2 | F | T | F |
| 3 | T | F | F |
- Test 1 & 2: Only A changes (T→F), B is T, outcome changes (T→F).
- Test 1 & 3: Only B changes (T→F), A is T, outcome changes (T→F).
This satisfies MC/DC.
Why is MC/DC Important?
- Thoroughness: It ensures that each condition in a decision is tested for its individual impact.
- Efficiency: It requires fewer tests than full condition coverage, but more than simple decision or condition coverage.
- Safety: Required by standards like DO-178C for avionics software.
Summary Table
| Coverage Type | What it requires |
|---|
| Statement Coverage | Every statement executed at least once |
| Branch/Decision | Every branch (true/false) taken at least once |
| Condition Coverage | Every condition evaluated to true and false |
| MC/DC | Every condition shown to independently affect outcome |
In short:
MC/DC ensures that every condition in a decision is tested in such a way that you can prove each one can independently change the result of the decision. This is crucial for finding subtle logic errors in complex, safety-critical software.