BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Heckle Your Way to Better Tests

by Obie Fernandez on Dec 20, 2006 |

Like Jester, the Java program that inspired it, Heckle mutates your Ruby code, attempting to make your unit tests fail. The premise is simple: If your unit test doesn't choke on Heckle's mutated code, then you need to improve coverage. Especially in cases where the team writing the code is practicing Test-Driven Development, Heckle does a really good job exposing unused code.

According to lead author Kevin Clark, "Heckle works by using the ParseTree and RubyToRuby libraries to grab the abstract syntax tree of methods, modify them, and evaluate the redefined method before running your tests."

Heckle shouldn't replace a line-based code-coverage tool such as RCov, but makes a good complement, especially in the Ruby world. Ruby code relies heavily on single-line branches — whenever you use a ternary operator, or suffix a statement with an if or unless, you're creating a logical branch that line-based tools like RCov won't properly detect. (The examples given in introductory articles by both Kevin Clark and Aslak Hellesoy illustrate the concept vividly.)

I asked Aslak to describe how Heckle fits into good test-driven development, and he said, "RSpec/Test::Unit is your safety belt. RCov is your airbag. Heckle is your helmet, neck brace and full fireproof suit."

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT