What is the difference between block coverage and branch coverage?
Asked Answered
D

1

9

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

Doable answered 7/3, 2016 at 13:0 Comment(0)
A
21

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%
Anjelicaanjou answered 7/3, 2016 at 14:54 Comment(5)
Thank you for the simple illustrative example!Avellaneda
I am pretty sure there will only be 3 blocks in your given example; 1 and 4 are the same block.Testate
Quite possibly. I think I tested this with a tool that I had handy at the time but I don't right now. If a tool treats all of a program/function/method outside conditionals as a single block, block coverage in the example will be 67%, still different from branch coverage.Anjelicaanjou
How block coverage is different from line coverage ?Jakie
@SrinivasCharanMamidi that's a different question. Ask a new question yourself.Anjelicaanjou

© 2022 - 2024 — McMap. All rights reserved.