Modified Condition/Decision Coverage (MCDC) Coverage
Percentage of conditions that current test cases evaluate for independent impact on outcome
Since R2023b
Description
A decision is a compound Boolean statement composed of conditions that are simple Boolean expressions. If changing a condition changes the decision outcome while the other conditions stay the same, the condition impacts the decision outcome independently. To test whether a condition impacts the decision independently, test cases must check:
Whether changing the value of the condition makes the decision outcome
trueWhether changing the value of the condition makes the decision outcome
false
The MCDC metric measures how many of the conditions the test cases check for independent impact. An MCDC coverage of 50% means that the test cases check only half the conditions for independent impact on the decision. To obtain 100% MCDC coverage, you might need to refactor decision statements.
Polyspace Implementation
For each condition in your code, Polyspace® Test™ checks for two objectives:
Whether changing the value of the condition makes the decision outcome
trueWhether changing the value of the condition makes the decision outcome
false
A condition has MCDC coverage if the test cases check for both objectives. Polyspace Test calculates MCDC as a ratio of covered conditions and total conditions. For instance, consider this code:
int foo(int A, int B, int C)
{
if ((A||B)&&C)
{
return 1;
}
if ((A&&B)||C)
{
return 0;
}
return -1;
}Three conditions in
((A||B)&&C)Three conditions in
((A&&B)||C)
If you test foo with these test cases:
input = (1,1,0), output = 0
input = (1,1,1), output = 1
The tests cover the MCDC objectives of only C in
((A||B)&&C), resulting in an MCDC value of 1/6 ×
100 or 17%.
Examples
Version History
Introduced in R2023b