I just read Eric’s beautiful post on unit testing and it struck a chord (well several). He’s right on that testing “trivial” classes and code feels dumb…right up to the point where it saves your ass.
I am repeatedly (and humbly) amazed at how many tests I’ve written on code that was “too simple to fail” found bugs. This could be because I’m an awful programmer. I’m comforted by the thought that I’m not alone, though.
I actually did an internal junit / unit testing talk many years ago (before it was pervasive) and grabbed some “simple” untested stack class I’d written to test live during the talk. The very first test I wrote actually exposed a bug in the class that I was unaware of. It was so perfect, that I’m sure it looked staged.
I also like the quote: “People who never write tests do not grasp this concept.” There are a number of effects from testing that really need to be experienced to be understood. I’m not sure why, maybe because they deal with emotion. I guess you need to actually experience the difference between being afraid to change code because you’re sure you’re going to break something to feeling the freedom to refactor and fix problems because your tests tell you it’s ok. Or the difference between thinking code works and knowing it works with a mountain of evidence to back you up. Or the satisfaction of reproducing a customer problem in minutes by extending an existing test, fixing the problem, and verifying with the test, knowing it’s fixed forever.