Test coverage for many AND/OR conditions in one statement

The way I see this scenario is 1 happy path, and 4 potential points of failure. If each condition is pivotal to allowing true to be returned, then it would be reasonable to write:

  1. A single happy-path unit test, the only case where the logic returns true. And
  2. A unit test for each variable that could cause the check to fail, asserting that the single variable has the power to prevent the condition from passing.

I understand it's possible to write logic that passes these checks, but actually returns true when multiple variables are false... but I really wouldn't worry about cases like that unless you're working on a spaceship or something where life / death is involved. In almost all cases, the tester is just testing that the implementation fails on the failure of any variable.


A lot has been written about this topic, and your question seems to call for MC/DC.

There is a predicate consisting of multiple conditions that leads to a decision. Well known coverage criteria applied to the predicate in the question include:

  1. Decision coverage: Ensure the overall predicate is once true, and once false.
    This leads to two test cases, for example (T,T,T,T) and (F,T,T,T).

  2. Basic condition coverage: Ensure each condition is both true and false.
    This can also be achieved with two test cases: (T,T,T,T) and (F,F,F,F).
    Note that basic condition coverage need not imply decision coverage (example: "P AND Q" with test cases (T,F) and (F,T) meets basic condition coverage, but both evaluate to F, so does not achieve 100% decision coverage).

  3. Modified Condition / Decision Coverage (MC/DC). Combination of decision and basic condition coverage, "modified" so that it also requires that each condition must individually determine the outcome. The answer by Edwin Buck is a valid MC/DC cover (TTTT, FTTT,TFTT, TTFT, TTTF).
    In general, with N conditions MC/DC requires N+1 test cases as opposed to 2^N. As such, it strikes a good balance between rigor (each condition tested) and efficiency (testing all of 2^4 may not be necessary). The intuition behind this is exactly the reasoning in the answer by Adam Bates.

  4. Full condition coverage: Test all 2^N possible combinations.