Main Content

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 true

  • Whether 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 true

  • Whether 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;
}
Here, the code contains six conditions:

  • 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

expand all

Consider the function foo(), which contains three conditions.

int foo(int A, int B, int C){
    if(A||B&&C)
        return 1;
    return 0;
}

Consider these test cases.

Test Case 1Test Case 2

  • Input: Parameter values = (0,0,1)

  • Assessment: Return value = 0

  • Input: Parameter value = (1,0,1)

  • Assessment: Return value = 1

These two cases test whether changing the input A also changes the outcome of the decision. Because these tests check for the impact of one out of three inputs on the outcome, the MC/DC coverage is 33%.

Correction — Add Test Cases to Check Impact of All Inputs

In general, for a function with n inputs, complete MCDC coverage requires n+1 tests. Consider these test cases.

ABC(A||B&&C)
0010
0111
0100
1011

The test cases check the ability of each input parameter to independently switch the outcome, resulting in 100% MC/DC coverage.

Version History

Introduced in R2023b