Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for tools that will help me write test cases to cover all paths through a function in Javascript. Ideally, I'd like something that will spit out a list of combinations of parameter and property values that should be tested. However, if the tool simply told me which parameters and properties have an effect on the function, that would be very useful as well.


edit: I'm not certain that "branch coverage" is the correct term for what I'm describing. If "code exploration" is a better term (or anything else), please add a comment.

share|improve this question

closed as not constructive by gnat, Dynamic, Walter, ChrisF Dec 20 '12 at 12:25

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

If you're going to use a tool like this in a language that handles complexity like JavaScript does, just make sure it doesn't turn into a crutch or you'll just be maintaining code that's not as robust as it could be. Also, I'm curious, how can you hope to reliably establish code coverage in a language as mutable as JS? Methods can be applied to new object contexts and prototypes can be swapped out at any time. Functions can have params read from right to left allowing for infinite repeating patterns to the limits of memory if we so desired. – Erik Reppen Dec 20 '12 at 7:05
@Erik: ...and why would you intentionally write JS like that, for a typical use case? -_- – James M. Greene Jan 1 '13 at 15:46

Use Istanbul, the new pure JavaScript-based code coverage which tracks everything from branch coverage to function coverage.

For a simple illustration, check my blog post JavaScript Code Coverage with Istanbul.

share|improve this answer
I'll give you the benefit of the doubt here since you have a good SO standing, but please do post other answers here that do more than promote your own blog posts. :-) This post could easily end up being flagged for spam otherwise. – Martijn Pieters Dec 20 '12 at 8:32
I have zero intention to promote my own blog post. If there would have been another article explaining how to use Istanbul, that'll would be my first choice. – Ariya Hidayat Dec 20 '12 at 16:46
@MartijnPieters Do you know that Ariya is the author of Phantomjs and Esprima? I mean, most code coverage, static code analysis tools and a lot of testing tools in the javascript community are base on these two tools. I mean, it's pretty relevant that he redirect to his own blog post being somewhat I'd call an expert in this field. – Simon Boudrias Dec 31 '12 at 21:09
@SimonBoudrias: Nope, I was not aware of that. – Martijn Pieters Dec 31 '12 at 21:11

JSCoverage is a tool that measures code coverage for JavaScript programs.

JSCoverage works by instrumenting the JavaScript code used in web pages. Code coverage statistics are collected while the instrumented JavaScript code is executed in a web browser.

share|improve this answer
-1. According to its own webpage, JSCoverage measures line coverage, not branch coverage, as the OP asks (although from the question text, it seems that he is actually looking for a code exploration tool, not a coverage tool, which, however, JSCoverage also isn't). Also, it is ridiculously out of date: it boasts that it supports the complete language syntax described in the 3rd edition of the spec … which was released in 1999(!!!). Since then, two new revisions have been released, ES5 in 2009, and ES5.1, more than a year ago. – Jörg W Mittag Aug 22 '12 at 23:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.