Flexcover Branches Out

May 10, 2008 on 4:26 am | In Flex, Travel |

Just dropping a quick note to followers of Flexcover and the ongoing AS3 code coverage adventure. It’s been a super busy time at work for me, but I’ve found enough spare cycles to put together a working branch coverage feature. It’s pretty cool: instead of toting up the number of lines that were executed (and highlighting lines that didn’t run in the source view), it counts “branches” that were executed: every conditional that affects program flow is tracked to count whether it has evaluated false or true, and how many times. In other words, if (a == 1) {…} else {…} counts as two different branches, one for the if clause and one for the else clause. Even better, if (a == 1) {…} also counts as two branches: you will be able to tell if the if clause ever got skipped because a was equal to 1. Try doing that with line coverage!

This treatment applies to looping statements like while, do and for (since every loop has a conditional that either continues or leaves the loop), to the conditional operator ?: (which is essentially an if statement), and to compound conditions combined with || and && (the individual conditions are tracked separately, since some conditions cause others to be skipped). A function also counts as a “branch”, since one certainly wants to track whether a function was called or not.

Branch coverage also means that conditionals which occur on the same line will be counted separately, since they are distinguished by column number as well as line number. The source view currently shows the branch counts as colored superscript notations within the lines.

Finally, branch coverage reports also give one a simple complexity metric: what are the most complex parts of your code? Look for functions with a high branch count! Of course, one can calculate complexity in much more sophisticated ways, but it’s a start.

I’m hoping to get this release out there in the next few weeks.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Entries and comments feeds. Valid XHTML and CSS.
All content copyright (c) 2006-2007 Joseph Berkovitz. All Rights Reserved.