3.4.3 Another MC/DC example
Course subject(s)
Module 3. Structural Testing and Code Coverage
MC/DC requires practice. Let’s do one more example. Let’s suppose the expression we want to test is: (A && B) || C.
That’s the truth table:
Let’s start with condition A. We have tests 2 and 6.
- If we flip A in row 1 (TTT), the counterpart is row 5 (FTT). As the outcome of both are the same TRUE, tests 1 and 5 are not able to evaluate the outcome of A independently of the other conditions.
- If we flip A in row 2 (TTF), the counterpart is row 6 (FTF). As the outcomes are different, tests 2 and 6 are able to evaluate the outcome of A independently of the other conditions. We keep them.
- We keep flipping. Row 3 and its counterpart 7 are not able to independently evaluate A, as their outcomes are the same.
- Row 4 and its counterpart 8 are not able to independently evaluate A, as their outcomes are the same.
Let’s look at condition B. We have tests 2 and 4.
- If we flip B in row 1 (TTT), the counterpart is row 3 (TFT). Outcomes are the same.
- If we flip B in row 2 (TTF), the counterpart is row 4 (TFF). Outcomes are different, so tests 2 and 4 are able to evaluate B independently of the other conditions.
- We keep flipping. Row 5 and 7 have the same outcomes.
- Rows 6 and 8 have the same outcomes.
Now, let’s look at C. If you repeat the same procedure, you will find three possible pairs: (3, 4), (5,6) and (7,8).
Now, if we try to minimize the number of tests (after all, we know that we need N+1 tests, where N is the number of conditions, thus, 4 tests), we have two options:
- 2, 3, 4, 6. So, A is tested by 2 and 6, B is tested by 2 and 4, and C is tested by 3 and 4.
- 2, 4, 5, 6. So, A is tested by 2 and 6, B is tested by 2 and 4, and C is tested by 5 and 6.
Good!
Now, an exercise for you: can you expand this idea to a problem that is not boolean? Let’s suppose you are calculating the price of your product, and you have the following decision table:
Can you apply MC/DC here? We’ll discuss this in future weeks.
Automated Software Testing: Practical Skills for Java Developers by TU Delft OpenCourseWare is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://online-learning.tudelft.nl/courses/automated-software-testing-practical-skills-for-java-developers/.