Branch Coverage subset of Condition Coverage

closed account (4ET0pfjN)
Hi,

is branch coverage a subset of condition coverage. I think it is b/c when we cover each branch (or edge), it doesn't mean we cover each truth value, is that correct?

> is branch coverage a subset of condition coverage.

No.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

void foo( bool a, bool b )
{
    std::cout << std::boolalpha << "condition a: " << a << '\n' ;
    std::cout << std::boolalpha << "condition b: " << b << '\n' ;
    if(a)
       if(b) std::cout << "\t*** branch1 covered \n" ;
       else std::cout << "\t*** branch2 covered \n" ;
    else std::cout << "\t*** branch3 covered \n" ; ;
}

int main()
{
    foo( true, false ) ;
    foo( false, true ) ;
}


Output:
condition a: true
condition b: false
        *** branch2 covered
condition a: false
condition b: true
        *** branch3 covered


We have 100% condition coverage; but branch1 is never covered.
closed account (4ET0pfjN)
But if not all branches are covered, it means it is a subset, b/c subset means the items in it are contained in a larger universe, unless i have subset mixed up. So in other words, condition coverage is a superset of branch coverage, just as statement coverage is subset of branch coverage. Or do i got it mixed up...
Last edited on
Let me put it this way:

The set of of test cases required to achieve complete branch coverage is a superset of the set of of test cases required to achieve complete condition coverage.

closed account (4ET0pfjN)
I understand weakness of statement coverage, but can someone tell me weakness of branch coverage, this is how i see it:

eg:

if ( x > 0 && x < 100 )
//do this
else
//do that

so if I have test suite T with the two test cases as such: T:{(x=1), (x=101)} then I would have executed the TRUE and FALSE edges, so the 'weakness' is that it fails to consider each combination as in:

a) x>0 is F && x<100 is F //NOT tested
b) x>0 is F && x<100 is T //NOT tested
c) x>0 is T && x<100 is T //tested above
d) x>0 is T && x<100 is F //tested above

assuming that we want the minimal test cases to satisfy branch coverage. So why do we even need to test a and b? I mean if we cover all branches, isn't that a good enough software metric?

Any help appreciated.
> I mean if we cover all branches, isn't that a good enough software metric?
> so the 'weakness' is that it fails to consider each combination ...

Yes, that is what path coverage addresses - it is a more exhaustive metric than branch coverage.
http://www.bullseye.com/coverage.html#basic_path

Though, what is 'good enough' in testing software is a difficult question to answer. In practice, we test as much as possible, as early as possible, as often as possible.
Last edited on
Topic archived. No new replies allowed.