Download FirebugCodeCoverage-0.1.xpi
Recently, I’ve become interested in client side automated testing tools. When I found the Selenium plug-in for Firefox, I was blown away. I can record actions in my browser and play them back! No more manual testing of JavaScript code!
Researching a little bit more about automated testing tools led to the discovery of a metric called ‘Code Coverage’, a statistic that gives you a percentage of how much of your code executed during a certain period of time (usually while your automated test was executing).
Of course, I immediately thought of Joe Hewitt’s Firebug extension for Firefox, which includes a feature for JavaScript Profiling. The Profile feature of Firebug was similar to a Function Entry Code Coverage report, so I decided to modify the feature and release an add-on for Firefox that showed (at a file level) a list of which functions executed and which functions did not.

So, now, to test my JavaScript code coverage, I will write automated tests using the Selenium IDE plug-in for Firefox, hit the Code Coverage button in Firebug, and try to get my Code Coverage statistics in the upper 90%’s.
Screenshot Example of running the tool at yahoo.com

Download FirebugCodeCoverage-0.1.xpi.
Requirements (obviously)
- Mozilla Firefox
- Firebug Extension for Mozilla Firefox
Limitations:
- Does not include statistics on anonymous functions.
- Is limited to function (entry) code coverage, does not include other forms such as exit, statement, condition, or path code coverage. (Description: Wikipedia)
- Is my first Firefox add-on, so there was a learning curve involved.
Future Improvements:
- Automated integration with Selenium IDE (one button to run tests and do code coverage)
- Better display of results, instead of a big kludge of function names
- Additional types of coverage, depending on what options are available from jsdIDebuggerService
Update: After many requests and much self deliberation, I have decided not to update the plugin to work with newer versions of Firefox. Code Coverage doesn’t belong in the browser, it’s just the wrong place in the tool chain to have something like this. Code Coverage results need to be exportable, and the utility must be executable from the command line to use with unit tests and continuous integration.

Subscribe
Follow
18 Comments
Hi!
I’m trying to develop something similar to what you’re trying to do with Selenium and Firebug Code Coverage.
Do have any reference of how to do this integration? How to instantiate an add-on “A” into an add-on “B”?
Tks for the attention.
Rafael
Sure, I have all the stuff I used as a reference (particularly the link about “Extending Firebug”) over at delicious under the tag XUL
http://del.icio.us/zachleat/xul
This is an absolutely amazing plugin for Firebug! I was looking all over the net for something like this, and it was a PERFECT fit!
Of course, I’d love some more features :) Please please please add:
1) Support for nested function – OO-style. If there’s a class MyClass and a function MyFunction, it would be awesome if you displayed it like “MyClass.MyFunction”
2) Click to navigate to the definition of the function. Firebug already has a great code browser, it would be amazing to be able to click on a function name in your plugin and go directly to the place in code where it’s defined.
Hi,
I have a requirement (may be strange) as follows:
- Execute blackbox test cases using GUI
- Hopefully, there is a tool that can record all my actions while I execute blackbox test and play back.
- The tool should be able to export the recorded instructions as HTTPUNIT tests.
- I need in particular HTTPUNIT or any other tests basically to see the code coverage of JSP/JAVA files.
Is there anything for this?
Please help
Cool extension. Why don’t you publish it in Mozilla Ads-ons page?
It’s currently in the sandbox. They won’t make it public until it has a certain amount of reviews.
This is really good tool. I really like it as I am trying to automate any and all items that i can.
I do have one question though. I ran a selenium test and one of the items that code coverage picked up showed a function in both Function Called and Function Uncalled.
Why is this?
Thats my only question but its really good!
Well, it doesn’t report on nested functions inside of objects. So, for example, say you have two identical functions located inside two different objects.
YAHOO.util.Dom.getStyle()
DAVIDBURNS.getStyle()
would unfortunately both be reported as getStyle in the current plugin.
Top-notch! Thanks!
do you have a place where request features or submit bugs? it will be good if the columns size would be resizable, i have some calls to long uri scripts (.net weresource.axd with a chunk of encoded data on the parameters) and i’m not capable of view the functions called.
Well, it uses the default table structure given from Firebug. So, if that feature gets added into Firebug, it’ll be usable here. I don’t think I want to be the one to add resizeable columns though.
You could buy a higher resolution monitor? :P
Saw another tool for JavaScript code coverage in a link to my page, and it’s got command line, and line reporting!
http://siliconforks.com/jscoverage/
Source:
http://rplcodeline.blogspot.com/2008/03/javascript-code-coverage.html
Check out the hrtimer Firefox extension, which contains a both a line-by-line code coverage tool for Javascript and a call-graph profiler. The package is still in development, but it’s useful now.
Awesome Daniel!
Any plans for integration with Firebug?
Any hope to update it for firefox 3.0?
VELO
hey, Zach, cool looking add-on, any word on it being compatible with FF 3.0.10 or .11?
thanks,
Atg
hey, cool looking add-on, any word on it being compatible with FF 3.3?
thanks,
Hey guys, I’ve updated the article with information about the future of this plugin.
3 Trackbacks
[...] coverage tools for JavaScript exist: ProtoCov, the commercial JavaScript coverage Validator, and some sort of FireBug add on. But these are noted for future investigation as I have not used these. If you have used [...]
[...] 7. FirebugCodeCoverage [...]
[...] 7. FirebugCodeCoverage [...]