Tests are not (just) for testing!

“I don’t have to test that, because i know it working.”

At first glance this quote seems to make sense. The algorithm is working, any fool could see that, so it would be a waste of time and space to write a test proving the obvious. And its an explanation i have heard from senior and junior developers alike.

For me, that is totally beside the point. Of course he knows that it works! He wrote the darn thing, and i must at least assume that he tried to compile and run it before committing. Though even if the code is simple it will only tell me what it does, not why.

I watch a unit test as a description of intent, more then anything else. A unit test can tell me what problem a function is designed to solve when the code itself tells me how it is solved. Just as for the rats in Hitchhikers guide to the galaxy sometimes just knowing the answer (42 by the way) isn’t enough, sometimes we need to understand the question as well.

Leave a comment