Branch vs decision coverage question

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>int fun(int a, int b) {
return (a > 5) && (b < 15);
}
</code>
<code>int fun(int a, int b) { return (a > 5) && (b < 15); } </code>
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>int fun(int a, int b) {
return (a > 5) & (b < 15);
}
</code>
<code>int fun(int a, int b) { return (a > 5) & (b < 15); } </code>
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if ((test1() || test2()) {
invoke_some_latent_bug_only_if_test1_is_false;
}
else {
do_something_benign;
}
</code>
<code>if ((test1() || test2()) { invoke_some_latent_bug_only_if_test1_is_false; } else { do_something_benign; } </code>
if ((test1() || test2()) {
    invoke_some_latent_bug_only_if_test1_is_false;
}
else {
    do_something_benign;
}

Suppose you have two test cases:

  • test1() evaluates to true, and
  • Both test1() and test2() evaluate to false.

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if( (a>5) || (b>6) )
{statements...}
else
{statements...}
</code>
<code>if( (a>5) || (b>6) ) {statements...} else {statements...} </code>
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 OR b>6
  • TC2: a<5 AND b<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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật