Modified Condition/Decision Coverage (MC/DC) is a method used in software testing to test highly critical systems.
MC/DC requires that all possible states of each condition must be tested while keeping other conditions fixed. Moreover, the change in an individual condition must be shown to alter the result.
Below are the four conditions to fulfill the requirements of MC/DC:
A condition is a boolean expression that cannot be divided further. A decision is a combination of conditions and boolean operators.
Consider the following snippet of code in C++:
#include <iostream>using namespace std;int main() {bool a = false, b = true, c = false;if(a && b || c){cout << "Inside the IF block" << endl;}}
In the above snippet of code, we have three boolean variables (conditions). Below is the truth table, which shows all possible values of those variables and the result of the boolean expression (decision) in line 7 of the above snippet:
Test No. | a | b | c | a && b || c |
1 | 0 | 0 | 0 | 0 |
2 | 0 | 0 | 1 | 1 |
3 | 0 | 1 | 0 | 0 |
4 | 0 | 1 | 1 | 1 |
5 | 1 | 0 | 0 | 0 |
6 | 1 | 0 | 1 | 1 |
7 | 1 | 1 | 0 | 1 |
8 | 1 | 1 | 1 | 1 |
Both possible states (0/1) of each variable have been tested in the above table while keeping the other two variables constant. Moreover, the decision produced by these conditions is in both possible outcomes at least once.
Test numbers 0 and 1 show that the variable c
can alter the result independently while keeping the other two variables fixed. Test numbers 5 and 7 show that b
can independently alter the value of the result. Test numbers 3 and 7 show that a
can independently alter the result. Hence, we will choose test numbers 0, 1, 3, 5, and 7 as our test cases.
Free Resources