Thursday, January 8, 2015

Saff Squeeze on recursive code with NCrunch

NCrunch makes all unit testing better, but there's something cool that happens when combining it with the Saff Squeeze, and something even cooler when the code under test is recursive.

In case you missed Kent Beck's Saff Squeeze:

The Saff Squeeze, as I call it, works by taking a failing test and progressively inlining parts of it until you can't inline further without losing sight of the defect. Here's the cycle:
    1. Inline a non-working method in the test.
    2. Place a (failing) assertion earlier in the test than the existing assertions.
    3. Prune away parts of the test that are no longer relevant.
    4. Repeat.
(I add Step 0; make a copy of the failing test.)

NCrunch helps because you can quickly see how far in the test you're getting until an assert fails. If the code under test is recursive, then:
Repeatedly incline the recursive call until NCrunch's code coverage dots show uncovered code.
Now your test does its job without any recursion, and you can continue to apply the Saff Squeeze as normal.

No comments: