Ian Bicking: the old part of his blog


"Unit tests are good, but unit tests do not make code *beautiful*"

I completely agree, but this misses a common approach to the use of unit tests. Kent Beck advocates a cycle for any given test that positively does *not* say that you are done when your tests pass: in fact you're only past the second phase. He recommends that (1) you write a failing test, (2) you get the test to pass and then, crucially, (3) you refactor. (I think Kent Beck characterises it as 'remove duplication'.)

(3) can take much longer than (1) and (2) put together, not least because this stage can end up with rewriting quite a lot of code not related to the test if opportunities for improved structure emerge. This is the opportunity to make the code beautiful. The unit test gives you a better chance of not breaking the code during this process.
Comment on Testing considered harmful
by Ian Griffiths