Humanized test coverage
Posted 14 August 2006 @ 9pm | Tagged software, thoughts
Rails still doesn’t offer a very good test coverage tool. Sure there’s rcov but it’s painfully slow, and I found it to be quite inaccurate, though to be fair I have only played with it a little bit. The other day I stumbled across a cool way to do test driven development with rails, right from The Wiki. The premise is that you name your tests in the form test_should_do_something_cool, and the have a rake task that harvests test names from each controller and prints them as english sentences. The task can be found on the wiki page so I won’t repeat it here, but what I did add was a method to my webapp that invokes the rails task to give me a coverage report right from the web:
def coverage
output = `cd #{RAILS_ROOT}; rake agiledox`.gsub!("- truth","<span style='color:red'>default truth method</span>")
render :inline => "<pre>" + output + "</pre>"
end
What i’m doing there is highlighting in red any controller that still has the default “test truth” method in it so that it stands out. The output looks something like this:
groups_controller should:
- successfully create group with creator as member
- send email and create pending membership when user wants to join restricted group
- add user when pending membership is approved by group creator
Not quite real test coverage but at least it gives you a sense of what kind of test you have.



No Comments Yet