REST API Specialist in continuous integration Code alchemist Roch Delsalle Leader in performance and mobile affiliation in Europe, Latin America and the region of the Middle East.
5 lines covered : 80 % 1 out of 2 branches covered : 50 % if(cond) { line1 line2 line3 line4 } else { line5 } If your test only goes in the cond being true and never runs the else branch : You would have:
: 100 % Branches covered : 50 % def testMe(cond1:Boolean, cond2:Boolean) = { if (cond1) line1() if (cond2) line2() } If your test only goes in the cond1 being true and cond2 being true: You would have:
: 100 % Branches covered : 50 % def testMe(cond1:Boolean, cond2:Boolean) = { if (cond1) line1() if (cond2) line2() } If your test only goes in the cond1 being true and cond2 being true: You would have: In order to get 100% branches covered, you will have to add a test with cond1 and cond2 as false
level coverage for this example You write two lines of Scala 1rst line compiles to 100 bytecodes 2d line compiles to 10 bytecodes If you have only tested line 2 you would get 9% coverage, when it should be 50%