Pragmatic me

The blog

My first attempt at the GOOS Auction Sniper

This is the first in a series of posts about Growing Object-Oriented Software, Guided by Tests (GOOS) by Steve Freeman and Nat Pryce. In this post, I describe my introduction to the book, and why I committed to completing the book and its worked example; the Auction Sniper.

How I discovered TDD

I discovered unit testing in around 2003, and test first development a year or two later. At this time, my tests were primarily integration tests written in C# using NUnit. I developed a few systems using this approach writing thousands of tests, and becoming more and more frustrated with slow execution speeds and the complex test setup required to write such tests.

When I first discovered test isolation and mocking, I saw them as a way of speeding up tests, and reducing test setup. I was happy to benefit from the former, but less so the reduction in setup. It took a while for me to start listening to the tests. TDD was still fairly immature, and the rapid evolution confused me - I struggled with the often competing idioms such as Don't mock what you don't own, Mock 3rd party dependencies, Mock commands and stub queries, not to mention the Mockist / London School vs Classic TDD debate.

How I discovered GOOS

I initially heard about GOOS at Agile Staffordshire in 2010, and read the chapters up to the introduction of the auction sniper worked example. These chapters struck many chords with my discovery of TDD, and in particular advocacy of mocking as a design tool. However, I never completed the Auction Sniper worked example; I was too busy learning Ruby and Clojure at the time and thus wasn't confident enough to attempt a translation. I relegated GOOS to my 'to-read' list.

GOOS at WMRUG

I've been attending the West Midlands Ruby Users Group for a couple of years and frequently discussions turned to unit testing. I recall several conversations with Andy Henson (@elaptics) about 'better' object orientation than that commonly seen in Ruby on Rails projects, how Rails can be difficult to test, and how test-driven development with isolation could benefit Rails development. GOOS was mentioned several times, and my suggestion to read the book was validated by Steve and Nat' interview in a recent Ruby Rogues episode.

The recent 'Is TDD Dead' debate and conversations with colleagues about the values, costs, and frequent brittleness of isolated unit tests spurred me on to attempt the book again. I suggested to Andy that we complete the book together and auction sniper challenge using Ruby.

Recalling my first brief attempt at the worked example, I knew using MRI Ruby would pose several challenges. RSpec is a significantly different testing framework than JUnit on which the book is based. Also, MRI Ruby doesn't have a UI framework similar to Java Swing as used within the worked example. Other complications like threading support, and static / duck typing would also complicate matters.

For this reason, we decided to use JRuby, and attempt to keep as true to the book as possible - using Swing via JVM interoperability. We would, however, attempt to use RSpec and the Vines XMPP server.

The next post in the series will discuss the complications I faced in using JRuby to complete the auction sniper, and why I decided to complete the worked example in Java before revisiting using JRuby.