February 14, 2008

...Learn TDD with Codemanship

The Limits Of Unit Testing Are No Excuse For Skimping

Yes. I know.

You cannot prove that your software works with unit tests.

It's a truism that's thrown at me every time a development team wants to justify spending less time and effort on their unit test assurance.

OK. You got me. I'm banged to rights. Don't worry about unit tests. Maybe you just need acceptance tests. Or integration tests. After all, unit tests don't check that all the components will work together. Right?

You drive a car, though? It was probably road tested after they built it, just to make sure all the components parts work together the way they were intended to.

How would you feel if I told you that the individual components of your car weren't thoroughly unit tested before they were integrated with the whole? Would you feel as safe driving it? Would you happily bundle the wife and the kids and the dog and cruise down the highway at 80mph for hundreds of miles knowing that your brakes were never individually tested?

And if your brakes fail, that means you car fails. When I take my car for an MOT every year, they check the brakes, and they check the tyres, and they check a whole bunch of other components individually to make sure they still function correctly. My car is not safe to drive if any of these components is not fit for purpose. And I don't want to die just yet, so I want high levels of assurance that my car will be safe to drive at all times. In between MOTs, I check my tyres, brakes, oil and wotnot pretty much every time I get in the damn thing (which is not often, living in London.)

So, yes. You are spot on that you cannot prove anything by unit testing alone. But that is not an argument to skimp on - or even skip - unit testing. Far from it, in fact.

Posted 10 years, 5 months ago on February 14, 2008