Tuesday, September 11, 2007

How do you make your 'Test Infection' more contageous?

I was first 'Test Infected' when I was working for a tiny consultancy, working on a project for a company who made games for Sky set-top-boxes. This was the first time I had really written any unit tests, and I quickly came to rely on them. I have been writing unit tests ever since then, but as time has gone on, the quality and nature of my tests has changed substantially. I've learned to develop code by asking 'What should this do?' rather than 'How should this work?'.

I have been fortunate to work with exceptionally talented people, who have helped me learn this practice. Now I find myself in an environment where there are lots of tests, but the code is not 'Test Driven'. It really shows in the codebase, that these tests are functional rather than unit tests, and that the tests did not come first. It is evident that the people who wrote these tests did what the believe to be the right thing.

The question is: How do you overcome the pattern of test-last development, and convince people to catch the TDD disease? It's a difficult switch to make, and it requires discipline. I'm in a position now where I'm trying to introduce TDD, but I have a team who think they are already doing it. Well, wish me luck!

1 comment:

Steve Purcell said...

Such a common issue. Knowing the JUnit API isn't the same as knowing how to write a unit test.

It's a challenge, but I think the solution is leading by example again; you refuse to write any code until there's a test for it.

It also helps if you can write a portion of the system completely test-driven, then rather than trying to hold ownership of that code to keep it "pure", you actively push other people towards that code and explain why it is the way it is.