Friday, June 13, 2008

Tests make you write better code

Michael Feathers has an article about Unit Testing that’s going around. The gist is:

“All of these techniques have been shown to increase quality. And, if we look closely we can see why: all of them force us to reflect on our code.”

I’m feeling that very directly right now. A client project I’m working on doesn’t have any tests, other than the skeletons Rails creates, which don’t run cleanly anymore. So we’re running without tests, which I haven’t done in a long time on any kind of serious project.

What I’ve discovered is that I make a lot more stupid mistakes that I never would have made with a decent test suite. It’s not that the tests would catch the mistakes. I never would have made them to begin with. From really questionable naming choices to silly little thinkos, I keep going back to revisit things and I say to myself, “Wow, what were you thinking?”

I wasn’t. Not as much as usual, since I didn’t stop and think about the test first.

What do you do when you come on a large project with no test suite, and no budget for retroactively creating one?


Follow me on Twitter. I don't have comments enabled, because I remember when we didn't have blog comments, and we did just fine, thank you very much.