froglogic logo

MC/DC Code Coverage Example

A sample C/C++ function with a decision composed of OR and AND expressions illustrates the difference between Modified Condition/Decision Coverage and a coverage of all possible combinations as required by MCC:

1
2
3
4
5
6
7
bool isSilent(int *line1, int *line2)
{
    if ((!line1 || *line1 <= 0) && (!line2 || *line2 <= 0))
        return true;
    else
        return false;
}

For 100% Multiple Condition Coverage a total of seven tests would be required. The “modified” requirements of MC/DC, on the other hand, reduces the number of required tests to the five listed below:

!line1 *line1 < 0 !line2 *line2 < 0 Decision
TRUE FALSE TRUE TRUE
TRUE FALSE FALSE FALSE
FALSE TRUE TRUE TRUE
TRUE TRUE TRUE
FALSE FALSE FALSE

For completeness here are the two tests that MCC would require in addition:

!line1 *line1 < 0 !line2 *line2 < 0 Decision
FALSE TRUE FALSE TRUE TRUE
FALSE TRUE FALSE FALSE FALSE

About froglogic

froglogic was founded to create a best-of-breed cross-platform test automation tools. The froglogic Squish Testing Suite consists of the cross-platform and multi-language code coverage analysis tool Squish Coco and the GUI Test Automation Tool Squish GUI Tester. More details…

Find out more…

For more information on which code coverage levels are most appropriate for your application and how Squish Coco can generate the metrics you require please complete the form below.

     

    Full Name (required):

    Company Name (required):

    Your Email (required)