NetBeans Screenshot of the Week #39: Ruby Code Coverage, Python Code Coverage

Here's a new feature for NetBeans 7.0: Code Coverage support!

First a screenshot:

There are a couple of key points about the code coverage support:

  • It is fully integrated into the IDE, and especially the editor. You don't get read-only views of your files with coverage information; the files themselves include coverage highlights. You can view and edit the code directly, use your normal IDE navigation commands to jump around, and so on.
  • Enabling and disabling code coverage is trivial. There is no need to modify your build files, run special rake targets etc. Just select the menu checkbox to enable coverage in the new Code Coverage project menu, and then continue as before - run unit tests, run files, run the tests in your project - and the results are updated live as soon as the executed process finishes.

I didn't think a screenshot really described this feature well, so I recorded a couple of quick sessions where I use the feature:

Here's a couple more images if you have problems loading the videos:

<script type="text/javascript">
digg_url = '';
<script src="" type="text/javascript"></script>

The Python version is already in the 7.0 builds. The Ruby support isn't integrated yet; it probably needs some tweaking to make it work on Windows.


Hi Tor,

Nice explanation of the available features.


Posted by Amit on December 16, 2008 at 11:32 AM PST #

Looks very cool! Thanks for posting, Tor!


Posted by Peter on December 16, 2008 at 04:27 PM PST #

Awesome. This just keeps getting better.

Posted by Jan Maurits Faber on December 16, 2008 at 04:31 PM PST #

Hi Tor,
Were can I download this mystical 7.0 version to try?
I tried Ruby version but could not find this feature.

Posted by Nick on December 16, 2008 at 07:49 PM PST #

Nice one. I might consider using Netbeans instead of Intellij sometime. My last experience with Netbeans was not very pleasing.

By the by, I was wondering why most of the time if Sun is posting a screenshot, the application is running on a mac rather than solaris?

Posted by Prabhu on December 16, 2008 at 08:54 PM PST #

Anything similiar for Java in the queue (out of the NetBeans Box)?

Posted by Sven Reimers on December 16, 2008 at 10:27 PM PST #

Hi all, thanks for your comments!

Nick, the Ruby version hasn't been checked in yet. It contains some platform specific code (well, Rake does, and the trickiest parts here was making code coverage work nicely with rake, so while my code works on OSX, I'm sure it won't work on Windows; I'm fixing that before checking in. I've spent the afternoon getting a Windows setup going.

Prabhu, when was the last time you used NetBeans? The reason I posted screenshots from OSX is that I use a Mac laptop most of the time, so posting screenshots from the Mac is most convenient. I used to do a lot of work from Ubuntu Linux, but I would use my Mac to post screenshots because the screenshots looked nicer (Linux had some font rendering issues). That's no longer an issue - so now it's just a matter of which desktop I'm happen to be using - usually a Mac. I've just gotten VirtualBox up and running and it's working beautifully, so I think I'll be running OpenSolaris a lot more than I have been, especially to get to the cool new JavaFX stuff which isn't available natively for the Mac.

Sven, there is already a code coverage module for Java that I've used in the past ( ). It's built on top of Emma. The UI has some issues (it's not using a highlighter factory but annotations instead which collide with hints and breakpoints in the gutter) but it's definitely functional enough. I think it should be pretty easy to retrofit the interesting parts of the Java module (which lives in the misc/ repository if youre interested) to the new coverage infrastructure I've written (like the rest of GSF, this uses small language specific plugins for Ruby and Python and most code is generic).

Posted by Tor Norbye on December 18, 2008 at 09:38 AM PST #

looks very cool! How long can the TextMate users hold off for..... :)

Couple of questions/comments:

Q1 - How did you run the tests in the video Tor? Just wasn't sure of what key combination you did to kick this off (just curious).

Q2 - Will Autospec integration work? That is, if one develops with autospec running, will it by default just keep updating code coverage accordingly?

Q3 - Is it possible to put in some shortcuts to automatically create or open the relevant spec? For example if you have an area of code with no coverage, click "open/create spec file".

Q4 - Is your implementation using "rcov"? If it was I'm wondering whether a shortcut to open up it's HTML reports with stats and everything would be useful to through in? i.e. just open up a browser to the index page of the rcov index.html page. (although I see you've already got some stats in what you've done yourself too)

Q5 - Will the bits drop formally via the update mechanism prior to Netbeans 7 Tor?

Q6 - Rake command accessibility via NetBeans menu? Did I miss something in the latest releases of Netbeans or did the menu to allow one to navigate through available Rake commands and run one drop off?


Posted by GregH on December 21, 2008 at 04:16 AM PST #

Hi GregH,
sorry for the delay.

All the code is checked in now, so you can take it for a spin.

Q1) To test the project I did Ctrl-F6 (on a Mac - not sure what it is on other platforms but the key combination should be listed in the context menu for the project). That runs all the tests in the project. To test a single file, I do Command-F6 (this is Test File in the Run menu) which will look up the test for the current file (if it isn't itself a test) and run that test under the test runner. And Command-Shift-T lets me jump back and forth between the test and tested file (this is Go To Test in the Navigate menu).

Q2) Autospec probably doesn't work. That will probably need some extra coordination; it depends on how autospec works (if it launches separate Ruby processes each time it should be pretty easy; otherwise we'll need to find a way to get it to dump its coverage state after each test run and then add notification to the coverage module to detect and update its state).

Q3) In the coverage report, the coverage data is sorted in increasing order of coverage (though if you're on JDK6 or later you can click on any table header to sort, for example to find the file with the largest raw number of uncovered lines). Double clicking on items in the report will jump to the corresponding file. Is that what you meant? Or do you just mean the normal Go To Test action? By the way, in the new builds I've added a code coverage editor bar with some extra information - like quick buttons to run all tests, open the report, the current file's coverage percentage, and a warning if the coverage data is older than the file.

Q4) Yes, for Ruby this is using rcov behind the scenes. Opening an HTML report isn't easy. The way this works is that every time you run, I'm invoking rcov in such a way that it dumps its line data to a file. RCov doesn't have a way (that I can find) to generate a report from dumped data. Thus, I would have to make rcov generate an HTML report every time just in case somebody wants to open it later. I'm hoping the report I'm providing will be just as useful such that you don't want the HTML report (which isn't editable, sortable, etc.) I'd like to add some more features to this; an editor sidebar with linecounts (like we have for version control annotations) etc.

Q5) The bits are in now - please grab the latest build and let me know if it works for you. I just (in the last hour) checked in a fix which makes the colors theme sensitive (and updated the ruby extra color themes module) so if you're using a dark color theme be sure to wait for build #4704 or later (and get an updated version of the ruby.themes color theme module if you're using it).

Q6) The Rake pullright menu was replaced by a new action, Run/Debug Rake Task... (Ctrl-Shift-R) which brings up a dialog which lets you quickly filter down to individual rake tasks. Perhaps there's a way to pin recent/frequently used targets - I'm not sure, I haven't played with it.

Posted by Tor Norbye on December 29, 2008 at 03:49 AM PST #

This is expectacular.

Posted by Jose Quesada on December 31, 2008 at 10:43 AM PST #

Post a Comment:
Comments are closed for this entry.

Tor Norbye


« July 2016