0

I have noticed that all the tests with no control-flow (such as if, else, switch, etc) shows 100% branch coverage due to no branch present in the code block. For example

def foo = {
println("Hello World!") 
}

Shows 100% branch coverage and 0 % statement coverage. This is due to 0/0 branch covered. From my eyes, I see one branch in above test case, so shouldn't there be one branch even if there is no control flow?

user_1357
  • 7,766
  • 13
  • 63
  • 106

1 Answers1

1

I guess its semantics. The code can only follow one path - so it can never "branch". Or do you consider the whole thing to be one branch.

If you have a train track which is a straight line, how many branches does it have ?

Does this have 2 branches, or 3 ?

def foo = {
  if (b) 
   println("1")
  else
   println("2)
}

At the very least I think we could update scoverage so that your example is 100% branch coverage, but should it say 0 branches or 1...

sksamuel
  • 16,154
  • 8
  • 60
  • 108
  • I see two branches in above example. You have a good point. However seen 100% coverage on a class just because it had not branch was confusing. Especially when there was no test for the class. – user_1357 Aug 10 '14 at 21:47
  • 2
    I suppose the rules should be, if you have 1 (or 0 branches), but no coverage then you have 0% branch coverage. If you have 1 or 0 branches and at least one statement covered, then you have 100% branch coverage. – sksamuel Aug 10 '14 at 21:51
  • One question, are you going to update the Scoverage witih suggested changes? – user_1357 Aug 12 '14 at 19:19
  • Next week turned into next month but its been committed now. – sksamuel Sep 05 '14 at 20:47