Links
Twitter
Flickr
« Automated testing and bravery | Main | Rails association extensions »
Wednesday
Apr302008

rcov: it is like crack for obsessive completists

rcov is a Ruby code coverage analysis tool that I've just been playing with for an hour or so while I look at how well my test cases are covering the code I've written.

You can gem install rcov

I'm working on a Rails app and there's a handy plugin to make running rcov easy peasy:

http://svn.codahale.com/rails_rcov/

with some documentation here:

http://blog.codahale.com/2006/05/26/rails-plugin-rails_rcov/

Now I can just rake test:test:rcov to run all my tests and see what they're covering.


Update: from playing around a bit I reckon that concentrating your coverage analysis around functional tests is probably the biggest bang for the buck. Functional tests exercise a lot of your code from both the controllers and the models.

rake test:functionals:rcov


rcov generates these amazing HTML reports telling you which code your tests exercised. More importantly it tells you which code your tests didn't exercise so you can work out what extra tests you need to add.

app_models_poll.rb - C0 code coverage information.jpg


How cool is that!

Now, what prompted all this was a post to the cc.rb mailing list about integrating rcov with a continuous integration build to fail the build if coverage drops below a certain acceptable threshold. Perhaps 80%? Perhaps 100% for those prone to collecting comic book series or trading cards.

There's a rails plugin named vl_cruise_control that will help with failing a build with cruise. I've not tried it yet.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>