1

I'm a little bit confused about code coverage criteria; especially condition and edge coverage.

As stated in this book, edge coverage does not subsume condition coverage; BUT my lecture material defines condition coverage in the following way:

Edge Coverage Criterion: Select a test set T such that, by executing a program P for each d in T, each edge of P‘s control flow graph is traversed at least once

Condition Coverage Criterion: Select a test set T such that, by executing P for each element in T, each edge of P‘s control flow graph is traversed, and all possible values of the constituents of compound boolean conditions are exercised at least once.

So, the first part of the definition of condition coverage is obviously the same as the whole definition of edge coverage. Hence, I thought condition coverage implies edge coverage ...

Is the definition broken? What's correct?

2

Based on your definitions, it looks like edge coverage does not imply condition coverage, but condition coverage does imply edge coverage. In other words, by covering all conditions, you will be guaranteed to cover every edge; but by covering every edge, you are not guaranteed to cover every condition.

For example,

int function(int arg1, int arg2)
{
    if(arg1 < 0 || arg2 < 0)
        return -1;
    else
        return arg1 + arg2;
}

Going by edge coverage, the edges here are "return -1", and "return arg1 + arg2"; in order to cover both of those edges, you need only two invocations:

function(-1, 0); function(0, 0);

There are, however, three conditions (considering the Boolean short-circuiting logic): arg1 < 0, arg1 >= 0 && arg2 < 0, and arg1 >= 0 && arg2 >= 0, so you'd need something like the following to achieve complete condition coverage:

function(-1, 0); function(0, -1); function(0, 0);

The key distinction in the definitions you posted is "and all possible values of the constituents of compound boolean conditions are exercised at least once". Covering all the conditions will ensure that you will hit all the edges. But as you see, covering all the edges does not ensure that you will hit all the conditions.

  • Are the terms condition/edge coverage well-defined? If you agree with me (based on the given definitions, condition coverage implies edge coverage), the referenced book seems to use different definitions. I've started wondering about the definitions, when I was asked to show "condition coverage doesn't imply path coverage" and later to show "edge coverage doesn't imply path coverage". But if condition coverage implies edge coverage, there is nothing more to show for the second statement ... – 0xbadf00d Dec 29 '13 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.