What is a branch in code coverage for javascript unit testing -


i use istanbul code coverage of unit tests in angularjs project. there 4 types of coverage , statement, branch, function , line coverage. statement, function , line allright don't understand "branch" is. explain branch is? thanks

a branch runtime can choose whether can take 1 path or another. lets take following example:

if(a) {     foo(); }  if(b) {     bar(); }  yay(); 

when reaching first line, can decide if wants go inside body of if(a)-statement. also, can decide not that. @ stage, we've seen 2 paths (one branch).

the next statement after gets more interesting. can go inside if body , execute bar. can not that. remember we've had branch before. result may vary if foo called or not.

so end 4 possible paths:

  • not calling foo, not calling bar either
  • calling foo, not calling bar
  • not calling foo, calling bar
  • calling both foo , bar

the last yay executed, no matter if foo or bar called, doesn't count branch. code snippet above contains 4 paths / 2 branches.

like other answers have mentioned, there numerous statements can cause branch (if/switch). don't forget conditional-loops, such while/for/do-while though.

the code coverage tool wants make sure you've tested branches. best if paths have been tested, not branches. this, make sure no unwanted behavior executed.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -