Posts

Showing posts from January, 2017

What is a Branch in angularjs code coverage

A branch is where the runtime can choose whether it can take one path or another. Lets take the following example: if ( a ) { Foo (); } if ( b ) { Bar (); } Yay (); When reaching the first line, it can decide if it wants to go inside the body of the  if(a) -statement. Also, it can decide not to do that. At this stage, we've seen two paths already (one branch). The next statement after that gets more interesting. It can go inside the  if  body and execute  Bar . It can also not do that. But remember that we've already had a branch before. The result may vary if  Foo  was called or not. So we end up with four possible paths: Not calling  Foo , not calling  Bar  either Calling  Foo , not calling  Bar Not calling  Foo , calling  Bar Calling both  Foo  and  Bar The last  Yay  is always executed, no matter if  Foo  or  Bar  was called, so that doesn't count as a branch. So the code snippet above contains four paths / two branches. Like other a