The Modified condition/decision coverage is one of the code coverage testing and can be categorized as white-box testing. It can bettered be explained with the help of a following code example:
if ((A && B) || C) then
{
/* code statements */
}
else
{
/* code statements */
}
For better understanding, shortly decision coverage testing and condition coverage testing will be discussed shortly:
In order to do 'Decision coverage' testing, the outcome of the logic condition needs to be tested for both True and False cases. Meaning, that condition variable can be set to such values that result in the output of the whole condition overall is True and false, each for once.
With, A = True, B = False, C = True => Outcome of the condition = True
A = True, B = False, C = False => Outcome of the condition = False
The above 2 set of inputs are enough to test the above piece of code with 'Decision coverage' test, instead of testing with whole truth table of A, B and C with 8 possible combination of values.
Then, comes the 'Condition coverage', in which each of the condition variables needs to be tested with both possible logic; True and False. So, the effect of each variable is observed when setting to both the logic; i.e. True and false.
A = True, B = False, C = True
A = False, B = True, C = False
With the above 2 set of input values, it would ensure 100% condition coverage test, as each of the variables is tested for both True and False.
However, both the Decision coverage and condition coverage tests are sometimes not enough to ensure the correctness of intended code flow. That is where Modified Condition/decision coverage test comes in. Which is often mandatory for safety-critical software to be performed on the code.
In Modified condition/decision coverage test, the effect of each condition variable on the overall outcome of the condition is tested. This is done by setting up input values of the condition, such as that each input variable is tested with True and False, with that affecting the overall outcome of the decision.
For example, for the same above example, let's set up set of input value for each of the condition variables, such as that the criteria is fulfilled:
1. A = True, B = False, C = True => Outcome of the condition = True
2. A = True, B = False, C = False => Outcome of the condition = False
3. A = True, B = True, C = False => Outcome of the condition = True
4. A = False, B = True, C = False => Outcome of the condition = False
So, if we look at the input value set no. 1 and 2, A and B are constant, but the value of C is changed. With C set to True, it results in an overall outcome of True and when C set to False, the overall outcome is also affected; changed to False. So, coverage for variable C is done. Similarly, B is tested in input values set no. 2 and 3. Where A and C are constant and with the change in the value of B, the outcome of the condition is changed. Also, same goes for input values set 3 and 4, in which variable A is tested, with variable B and C kept constant. In this way, as all variables have been tested and the effect on outcome observed, 100% MCDC is achieved.
It is worth mentioning that, for achieving 100% coverage for MCDC, only
[no. variables in the condition] + 1sets of input values/tests are necessary out of the total possible combination of all variables in the condition (2^3 = 8), as can also be seen in the above example.