Heckle Your Way to Better Tests
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
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."
Uwe Zdun, Rafael Capilla, Huy Tran, Olaf Zimmermann Mar 09, 2014
Olav Maassen, Liz Keogh & Chris Matts Mar 08, 2014