Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between block coverage and branch coverage?

Is block coverage the same as branch coverage, similar to it or completely different?

The top Google link explaining branch coverage: http://www.tutorialspoint.com/software_testing_dictionary/branch_testing.htm

like image 478
S V Avatar asked Mar 07 '16 13:03

S V


1 Answers

Block coverage (or "basic block coverage") and branch coverage are two different measures of code coverage. Block coverage counts blocks bounded by branches. Branch coverage counts the actual branches.

This code fragment

puts "I'm block 1"
if condition
  puts "I'm block 2"
else
  puts "I'm block 3"
end
puts "I'm block 4"

has four blocks but only two branches, the two sides of the if/else. If this code is tested by only one test and condition is true in that test,

  • blocks 1, 2 and 4 will be covered, so block coverage will be 75%
  • the true branch of the if will be covered but not the false branch of the if, so branch coverage will be 50%
like image 86
Dave Schweisguth Avatar answered Oct 23 '22 06:10

Dave Schweisguth