ISTQB does not distinct between these (it reads “Branch/decision coverage”) but some sources do say it is different.
I would have two question. The essential one is about the difference. And the other one – does this whole concept belongs under the unit testing? Or white box testing?
Thanks
From the ISTQB:
branch coverage is closely related to decision coverage and at 100%
coverage they give exactly the same results. Decision coverage
measures the coverage of conditional branches; branch coverage
measures the coverage of both conditional and unconditional branches.
The Syllabus uses decision coverage, as it is the source of the
branches. Some coverage measurement tools may talk about branch
coverage when they actually mean decision coverage. (c) ISTQB
foundation book.
1
The branch is an optional execution path, whereas a decision is the result of a combination of conditions (i.e. a boolean expression).
Thus, there can be decisions without branches.
For example:
int fun(int a, int b) {
return (a > 5) && (b < 15);
}
In the above function, (a > 5)
is a condition, (b < 15)"
is another condition. (a > 5) && (b < 15)
is a decision. And there is no branch.
Thus in this example, the decision coverage will be reached with only 2 tests, and the branch coverage on source code reach 100% with a single test.
Branch coverage at the assembly level would require the same two tests, but the question becomes tricky if you write the function like this:
int fun(int a, int b) {
return (a > 5) & (b < 15);
}
There is still a boolean decision (computed with arithmetic operations) and the assembly would not have branches.
NASA’s handbook on MCDC measurement clarifies this type of difference:
https://ntrs.nasa.gov/citations/20010057789
4
Here’s the problem in a nutshell:
if ((test1() || test2()) {
invoke_some_latent_bug_only_if_test1_is_false;
}
else {
do_something_benign;
}
Suppose you have two test cases:
test1()
evaluates totrue
, and- Both
test1()
andtest2()
evaluate tofalse
.
Some code coverage tools will yield 100% coverage because these two test cases result in the execution of every statement. The problem is that every path has not been tested. This code needs three test cases, one more for the case where test1()
evaluates to false
but test2()
evaluates to true
.
In this hypothetical example, that third critical test case would expose that latent bug. If you fail to provide that third case and use a coverage tool based solely on statement executions you will get a false sense that testing is complete.
2
If you think about your program as a big directed graph with a start node going to one or more end nodes. Each statement in your program is a node on the graph, branches or decisions are edges between nodes.
Full statement coverage is when you visit every node in the graph at least once,
full branch/decision coverage is when you traverse every edge in the graph at least once (and I think they are the same thing).
Neither of these is necessarily the same as Full path coverage, when you traverse every path from the start node to every end node.
As with any terminology there is no guarantee that everyone means exactly the same thing by the same term. Wikipedia seems to take branch coverage to mean modified decision coverage but there are plenty of other sources, as you note, that say they are the same. What we can say more authoritatively is that statement coverage is not the same as branch coverage, and neither are the same as path coverage.
If you need to use these terms then your best bet is to define what you mean by them before you use them.
For point 2. Coverage metrics can be used on any form of testing, it is certainly fairly common to use it on unit tests and on automated system/integration tests
9
Branch coverage is like doing TRUE and FALSE, but in decision coverage, you need to go through each condition.
For example:
if( (a>5) || (b>6) )
{statements...}
else
{statements...}
In this scenario for branch coverage, you need to simply make the if condition true then false as well.
- TC1:
a>5
ORb>6
- TC2:
a<5
ANDb<6
but for the decision coverage, you need to consider the boolean table and need to satisfy each of the conditions.
TC | a | b | RESULT |
---|---|---|---|
1 | a<5 |
b<6 |
FALSE |
2 | a<5 |
b>6 |
TRUE |
3 | a>5 |
b<6 |
TRUE |
4 | a>5 |
b>6 |
TRUE |
2