Testing Unit Coverage – Is Path Coverage Stronger Than Condition Coverage?

test-coveragetestingunit testing

I have encountered (even in literature) two contradicting opinions related to path vs condition coverage (not branch or edge!). Some say Path coverage is stronger than the condition coverage, some say the opposite.

Having code like this:

If(X<0 OR X>100)
   DoStuff();

Path coverage – 1 test case is needed to cover the path. With X=-1, the second expression will not be tested and possible bug will be missed.
Condition coverage – test cases X=-1 and X=100 are needed to test both conditions.

Am I missing something or condition coverage is really stronger than path coverage?

Condition coverage (ISTQB):

Our next level of coverage is called condition coverage. The basic concept is that, when a decision is made by a complex expression that eventually evaluates to TRUE or FALSE, we want to make sure that each atomic condition is tested both ways.

Practical Insight Into CMMI

Condition coverage measures the true and false outcome of each Boolean
subexpression.

References:

Software Testing: Principles and Practices from Srinivasan Desikan,Gopalaswamy Ramesh: page 61

Condition coverage is a much stronger criteria than path coverage,
which in turns is a much stronger criteria than statement coverage.

Best Answer

Neither one is "stronger" in the mathematical sense:

  • Path coverage does not imply condition coverage, as illustrated by an example in your question
  • Condition coverage does not imply path coverage, as illustrated by your comment (condition IF(A&&B) with pairs A=TRUE, B=FALSE and A=FALSE, B=TRUE).

This means that claims that either side is somehow "stronger" would be invalid.

If you "upgrade" the condition coverage to modified condition/decision coverage, however, the answer would be "yes": MC/DC always implies covering the path, but covering the path may not necessarily imply even covering the condition, let alone MC/DC.

However, this does not imply that 100% MC/DC is always better than path coverage: the tradeoff is that it comes at much steeper "price" than a 100% path coverage due to the need to write more tests. Sometimes, a lot more. This has a potential of complicating the maintenance of your test suite.

I think it is a good idea to maintain a good balance between condition/decision coverage and path coverage by path-covering simple conditions (such as argument checks of the "null or empty" sort) and condition/decision-covering statements with complex business logic.

Related Topic