Search code examples
testingcode-coveragemc-dc

Minimal set of test cases with modified condition/decision coverage


I have a question regarding modified condition/decision coverage that I can't figure out.

So if I have the expression ((A || B) && C) and the task is with a minimal number of test cases receive 100% MD/DC.

I break it down into two parts with the minimal number of test cases for (A || B) and (X && C).

(A || B) : {F, F} = F, {F, T} = T, {T, -} = T
(X && C) : {F, -} = F, {T, F} = F, {T, T} = T

The '-' means that it doesn't matter which value they are since they won't be evaluated by the compiler.

So when I combine these I get this as my minimal set of test cases:

((A || B) && C) : {{F, F}, -} = F, {{F, T}, F} = F, {{T, -}, T} = T

But when I google it this is also in the set: {{F, T}, T} = T Which I do not agree on because I tested the parts of this set separately in the other tests, didn't I?

So I seem to miss what the fourth test case adds to the set and it would be great if someone could explain why I must have it?


Solution

  • Recall that for MC/DC you need for every condition P (A/B/C in your case) two test cases T and T' so that P is true in T and false in T', and so that the outcome of the predicate is true in one and false in the other test case.

    An MC/DC cover for ((A || B) && C) is:

    • T1: (F, F, T) -> F (your first test case)
    • T2: (F, T, T) -> T (B flips outcome compared to T1, missing)
    • T3: (T, F, T) -> T (A flips outcome compared to T1, your third test case)
    • T4: (F, T, F) -> F (C flips outcome compared to T2, your second test case)

    In concrete test cases you cannot have "-" / don't-care values: You must make a choice when you exercise the system.

    So what you are missing in your answer is a pair of two test cases (T1 and T2) in which flipping only the second condition B also flips the outcome.