Nat Pryce has some good ideas about writing test code
Nat Pryce over at Mistaeks I Hav Made has an interesting series on writing test code, starting with Test Data Builders and then enhancing the technique with
- Define common state and avoid aliasing problems
- Combining builders
- Emphase the domain model with factory methods
- Factoring out duplicated logic creates a domain-specific embedded language for testing
This is the kind of stuff that makes me feel good about programming as a craft – the equivalent of having a master carpenter sit down with you and explain how to make a really clean dovetail joint.
Of course, the techniques he describes aren’t just for test code. I enjoy reading and maintaining applications designed with this sort of literate, readable structure.