scalacode-coveragescoverage

Scoverage: Ambiguous measurement from branch coverage


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?


Solution

  • 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...