Thursday, April 17, 2014

Interesting KataCast: "Clojure TDD demo (Robozzle)"

I've just watched this great explained katacast by Brian Marick

The top-down style Marick uses to grow his code through TDD reminds me a lot of how Gregor Kiczales worked through the example programs in Racket of his Introduction to Systematic Program Design - Part 1 Coursera course that I took a while ago.

The difference between the two processes is basically in the tooling, because Midje allows Marick to "stub" the results of helper functions so he can get feedback about his top functions from the very beginning whereas in Kiczales' examples he had to wait until all the helpers were working to see the top functions tests pass.

Apart from that they use the same top-down approach.

Interesting Talk: "Some Thoughts on Classes After 18 Months of Clojure"

I've just watched this great talk by Brian Marick:

Friday, April 11, 2014

Standard Output redirection in Java for a characterization test

Last weekend I did the UglyTrivia legacy code refactoring kata in Java.

Before starting to refactor, I added a characterization test to describe (characterize) the actual behavior of the original code. Since the only "visible effects" of the code were the lines it was writing to the standard output, I had to use that output to create the characterization test.

This is the code of the characterization test:

Although in this final version, the expected output reflects the fixing of two bugs in the original code, at the beginning it was just what the original code was writing to the standard output given a fixed seed for the random number generator.

This article describes this technique very well: Working Effectively With Characterization Tests.

To be able to redirect the standard output I used the StandardOutputRedirection class:

The characterization test shown before yielded a code coverage of 93% which gave me confidence enough to start refactoring the code.