TDD Masterclass

I recently attended a two day TDD training course by Jason Gorman.

Although we practise TDD on a daily basis, I was interested to see if we are applying all the practises correctly or see if we are missing out on anything.

The Jason presented what he called the baker’s dozen of TDD practises.

  1. Write a failing test
  2. Write the assertion first
  3. Don’t refactor with a failing test
  4. Isolate tests from each other
  5. See the test fail
  6. Triangulate
  7. Organise tests to reflect model code
  8. Write the simplest code to pass the test
  9. Choose meaningful names
  10. Test one thing in each test method
  11. Refactor to remove duplication
  12. Keep test and model code separate
  13. Maintain your tests

The great way Jason reinforced these practises was to apply another great agile practise, pair programming. In pairs we applied TDD to solve various programming problems, e.g. generating Fibonacci numbers, FizzBuzz, etc. Solving these problems in pairs was the most enjoyable aspect of the course. By enforcing frequent pair rotation I met a lot of nice people plus I even got a taste of TDDing in C#!

So what did I find in the end? We are doing pretty well at youDevise. We nearly apply all the practises (we can probably do triangulation more). Overall, I think the course is a good introduction to TDD, especially learning through pair programming.

Doing things the old way

We’ve been talking recently about why we get stuck in processes that no longer serve our needs even though they were the right thing when we started.

There were a few things that came up: tests written in particular ways, particular sign-offs in our development cycle, the idea that we must have certain types of tests, writing code in particular ways, and so forth.

There was a bit of defensiveness when unnecessary things were highlighted. We didn’t set out to be inefficient, and we wanted to explain the context that made these things good ideas. Understanding that context and understanding where we’re at now are both important for positive change. Lack of understanding just fuels defensiveness.

An experience of mine is a good metaphor:

Years ago I broke my left knee in a motor accident. I was very careful to do as I was told during my recovery and have since restored symmetrical strength and flexibility. (I even went on to do several years of regular fencing practice.)

Recently I’ve started Aikido classes and a basic training technique requires falling backward when thrown: lower yourself down with the rear leg and roll smoothly on your back, a very safe and effective way of falling. I can do this easily with my right leg but I always hesitate with left leg — I hop back awkwardly or I fall and land heavily on my butt. I learned to defend my left leg after the accident, and I’m still unconsciously defending it long after the need has passed.

Now I’ve got pressure on me to change. I’m getting to the mats early and practising that backward roll slowly and gently so I know what it should feel like. I’m paying attention when it turns out right in class and trying to remember those successes more than the failures. I speak to other students and the instructor so that they give me the chance to practice it right. Eventually the right move will become unconscious. Who knows but maybe losing the habitual defence is the last stage of healing for that old injury?

Some of our quirky processes may be the same. At a time of need we carefully included steps which now are not needed. We’ve learned our lessons, but we’ve spent so long valuing them as necessary defences that it’s hard to let them go. In fact, without some external perspective or change to bring them to our attention, we don’t even notice that we’re doing anything odd.

The puzzle is how to drive positive change. If my broken leg metaphor is right we need things like: a problem that highlights the cost of now unnecessary practices, recognition of why they were valuable and re-assessment of our current condition, recognition of our growth and trust that we won’t backslide, and alternatives that we can practice that might also allow us to grow even further.

In the end an up to date set of development processes and techniques should make our day to day work more comfortable and effective, that’s worth the effort.