Condition coverage is about testing that any operands which are part of the if
expression can be evaluated to both true
and false
without issues. In this type of coverage, you don't care about what would be executed inside the braces, nor about the result of the operand used in a condition.
Take the following code:
bool a = ...;
bool b = ...;
if (a && b)
{
...
}
Condition coverage of this code would require to test:
a
for both true and false, and:
b
for both true and false.
In languages which require both operands to evaluate in a logical operation, condition coverage of the code above is satisfied with:
a = true; b = false
a = false; b = true
This is what is illustrated in your question.
Some languages evaluate the second operand of a logical AND only if the first operand is true (or evaluate the second operand of OR only if the first operand evaluates to false). In this case, three tests are required instead of two:
a = true; b = true
a = true; b = false
a = false
As you can note, we don't care about the value of b
in the third test, since the program will never compute it when a
is false.
Above all, you need to have and analyse combined (total) coverage. If you think of it, this is the most natural way to properly prioritize your risks and focus your test development effort.
Combined coverage shows you what code is not covered by tests at all, ie is most risky and need to be investigated first. Separate coverage reports won't help here, as these don't let you find out if the code is tested somehow else or not tested at all.
Separate coverage analysis also can be useful, but it would better be done after you're done with combined analysis and preferably would also involve results of analysing combined coverage.
Purpose of separate coverage analysis differs from combined one. Separate coverage analysis helps to improve design of your test suite, as opposed to analysis of combined coverage which is intended to decide on tests to be developed no matter what.
"Oh this gap isn't covered just because we forgot to add that simple unit (integration) test into our unit (integration) suite, let's add it" -- separate coverage and analysis is most useful here, as combined one could hide gaps that you would want to cover in particular suite.
From above perspective, it is still desirable though to also have results of combined coverage analysis in order to analyse trickier cases. Think of it, with these results, your test development decisions could be more efficient due to having information about "partner" test suites.
"There's a gap here, but developing a unit (integration) test to cover it would be really cumbersome, what are our options? Let's check combined coverage... oh it's already covered elsewhere, that is, covering it in our suite isn't critically important."
Best Answer
There is no advantage of byte-code or line coverage over branch coverage.
If one element (line or instruction) of a branch is covered, then all elements of that branch are covered as well.
If a single line of code contains more than one branch (e.g., in C:
(a==0) ? do_b() : do_c()
), branch coverage takes it into account.Moreover, branch coverage is completely independent from source code formatting.