Any time I do anything on the internet, I try to apologize for whatever it is that I’m about to do because I’m certain it’ll come across as completely amateurish and a colossal waste of time, and then I do it anyway and feel somewhat guilty about it. Ultimately I get discouraged and abandon all efforts to continue whatever it was that I had been doing, delete everything, and retreat into nothingness until years later, I’m struck with the urge to try again. I’m going to try to skip the first part of the cycle this time and hope the rest takes care of itself.
Recently at work, we’ve been a lot more aggressive about making efforts to unit test everything. I have to admit, while it was stressed as a rather good idea in school I was never really very fond of unit testing. After all, I had to be doing something along those lines anyway the whole time to make sure the product worked, so why should I spend the extra time to formalize the process? I’m rather unwilling to accept “because your boss/manager/whatever said so” as a worthwhile answer, so the whole time I’ve been writing said tests, I’ve been trying to find the redeeming value in them.
If nothing else, they’ve forced me to more carefully examine what it is that each specific method is supposed to do. Sure, I’ve placed a lengthy comment ahead of the method describing what its inputs are and what it does and I’ve manually “tested” each of them so that they do what I think they ought to do, but going through the process of writing up individual tests has helped me to ask myself a lot of the questions that QA might ask instead, and answer them in advance. Let’s say I’m writing a parser that’s supposed to return a match on any “printable character”. What, exactly, defines a character as printable? Are white-space characters “printable”? What about control characters?
I haven’t found and fixed any bugs as a result of my unit testing, but I have made the documentation of my code more precise. Has it been worth the time? I’d have a hard time saying yes, but at the same time, I couldn’t say that it hasn’t.