BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Heckle Your Way to Better Tests

Heckle Your Way to Better Tests

Bookmarks

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."

Rate this Article

Adoption
Style

BT