unit testing is teh suck, or is it?

I was read­ing about unit test­ing and I came across Wil‘s blog arti­cle: Unit test­ing is teh suck, which was dated back in 2005. That title looked like it was asking for a flame war (as it hap­pened) and it sounded very inter­est­ing to me right after I recently dis­cov­ered the value in Test Driven Development.

The arti­cle was great, with many valid point. One par­tic­u­lar com­ment from Shalev prob­a­bly sums up my view:

I feel as if a great light has finally dawned upon me. The dark hypocrisy’s of people yelling “Don’t Repeat Yourself!”, and then turn­ing around and writ­ing their appli­ca­tion twice have finally given way to the light of a new way. The fact is that code that fully tests an appli­ca­tion will always be bigger than the appli­ca­tion code itself. This has always grated against the grain of my least-code-possible pro­gram­mer soul. I thank you for finally val­i­dat­ing what I others claimed a defect in my pro­gram­ming nature.

The least-code-possible pro­gram­mer soul, huh? That’s my phi­los­o­phy all along.

So what’s my take on unit test­ing now? To test or not to test? I would say, be flexible.

From another of Wil’s arti­cle (forgot which one), he said some­thing along the lines of “When people first learned objec­tive lan­guages, they go and create a God class, which inher­its like 40 sub­classes each with prob­a­bly a couple of lines of code difference” That’s right, that’s prob­a­bly also the case for unit test­ing: when people first heard of unit tests, they became advo­cates. (For the case of unit test, per­haps more people run away than to become advo­cates, but you get the point)

Does that mean objec­tive lan­guages and OO are teh suck? No! It’s the master programmer’s deci­sion as to when to use what tools and when to not use them. These kinds of expe­ri­ence, instead of things like which lan­guage 0wnz which lan­guage, are what sep­a­rate generic pro­gram­mers from the true masters.

Unit test­ing in gen­eral is a good idea, but it becomes an anti-​pattern when one gets restricted by it: waste too much time writ­ing tests other than writ­ing actual code, obsess­ing over than 10% of code cov­er­age which is just a number (as high-​scores from video games) Sim­i­larly, I think com­pletely ditch­ing unit tests is a waste of such valu­able tools.

In the end, there is no need for black-and-white think­ing here, just do what feels right at the moment based on your experience.

8 Responses to “unit testing is teh suck, or is it?”

Leave a Reply