Monday, November 9, 2009

How many tests are enough?

I've been thinking recently, "How do I know when I've written enough tests?" The answer came to me in a scenario - I've just finished working on a complicated module, and somebody on my team says, "I need to change some of your code to make my stuff work."

Now, I don't know about you, but I'm protective of my code. It feels like one of my kids. I created it. I put my heart and soul into it. I'm proud of it. I want you to like it, admire it, respect it (and me), but I certainly don't want you messing it up.

So when faced with this scenario, what is my reaction? "No, don't touch that! It took me three days to write it." Or is it, "Sure, just keep the tests passing"?

To me, that sums up everything there is to say about test coverage. Not that test coverage tools and metrics aren't important. They give valuable feedback. But, the bottom line is that tests protect your code. Do you feel safe putting it out into the wild?