Basic vs. compound condition coverage

后端 未结 2 1587
情话喂你
情话喂你 2021-01-16 12:56

I\'m trying to get my head around the differences between these 2 coverage criteria and I can\'t work out how they differ. I think I\'m failing to understand exactly what de

2条回答
  •  清歌不尽
    2021-01-16 13:29

    Regarding terminology, I don't have a single source handy that uses the exact terms "basic condition coverage" and "multiple condition coverage". Binder's "Testing Object-Oriented Systems" says "condition coverage" and "multiple-condition coverage". Everett & McLeod's "Software Testing" says "simple condition coverage" and "compound condition coverage". But I'm certain that the first term in each case is your "basic condition coverage" and the second is your "compound condition coverage". I'll use those terms below.

    Basic condition coverage means that every basic condition in the program is true in some test and false in some test, regardless of other conditions. In the following

    if a && b && c
      # do stuff
    else
      # do other stuff
    end
    

    there is a compound condition, a && b && c, with three basic conditions, a, b and c. It takes only two test cases, one where all basic conditions are true and one where all are false, to get full basic condition coverage. It doesn't matter that the basic conditions happen to be part of a compound condition.

    Note that basic condition coverage is not branch coverage. If the compound condition were a && b && !c, those two test cases above would still achieve basic condition coverage but would not achieve branch coverage.

    A less aggressively optimized set of test cases for basic condition coverage would have one test case where all three basic conditions are false and three test cases with a different basic condition true in each. That would still only be four of the eight possible combinations of basic conditions in the compound condition. The uncomfortable feeling that we're ignoring the other four is why there's compound condition coverage. That requires a test for each possible combination of basic conditions in a compound condition. In the example above, you'd need eight tests, one for each possible combination of possible values of a, b and c, to get full compound condition coverage.

提交回复
热议问题