DC vs. CC vs. CDC vs. MC/DC
The "Code Coverage Types" parent page uses an example where not all code coverage types reveal their logical differences. This page provides an additional example to highlight these differences.
Consider a decision with two conditions: (A or B)
Decision Coverage (DC)
The below inputs satisfy the coverage. They toggle the decision outcome between true and false.
(TRUE/FALSE) --> True branch
(FALSE/FALSE) --> False branch
The problem: the effect of B is not tested. It is always FALSE.
As such, the above set of cases do not distinguish between the decision (A or B) and just A.
Condition Coverage (CC)
The below inputs satisfy the coverage. Both A and B use both outcomes.
(TRUE/FALSE) --> True branch
(FALSE/TRUE) --> True branch still
We can now confirm that B does have an effect.
The problem: The False branch (outcome) is never triggered.
Condition/Decision Coverage (CDC)
Combination of the previous two types. Both A and B outcomes are used, and both branches are reached.
(TRUE/TRUE) --> True branch
(FALSE/FALSE) --> False branch
The problem: These tests do not distinguish (A or B) from (A and B), which is logically different. For both decisions, the above tests would lead to the same result.
In other words, if anyone changed the OR operator to AND in code, these automated tests would still pass and would NOT detect a change.
Modified Condition/Decision Coverage (MC/DC)
This coverage type requires a more thoughtful test case selection, and, in general, a min of n+1 cases, where n is the number of conditions in a decision. For (A or B), we need 2+1 = 3 tests.
(TRUE/FALSE) --> True branch
(FALSE/TRUE) --> True branch
(FALSE/FALSE) --> False branch
Just like with CDC, all outcome values were used AND both branches reached.
But now, this set of tests distinguishes (A or B) from (A and B) and would thus detect a change.
Note that it is not always possible to follow MCDC "expectations". Among other things, MCDC mandates that each condition has been shown to independently affect that decision's outcome.
In other words, you must be able to toggle A value, while keeping all others constant.
But bear in mind that you often have exceptional compound decisions such as:
It has 4 atomic conditions, where the 1st A and the 2nd A are two separate conditions. Strictly speaking, you can't toggle the 1st A without toggling the 2nd A. But in practice - that's fine.
Last updated