Is Unit Testing Useful?

Man, within 15 minutes I read this post, by the Bill Morier, VP of software development at Justin.tv, throwing me into a loop and then I read this post by Jay Fields, talking about real-life testing processes. Another loop.

Let’s address both. First post is titled:”Unit testing is not (generally) useful”. Useful for what? Finding bugs. When I started unit-testing years ago, it was indeed to find bugs and fix them. Quality components make for better system, less painful integration. It didn’t find all the bugs, though.

Later in life, when I started doing automated unit tests and TDD, I saw more benefits. Courage to change my code, for example. Proof that my code works. Less debugging time. Still didn’t find all the bugs. And guess what? Never will.

But from there to saying that it’s not useful, is quite a long way. Especially when the guy mentions what he does find useful for finding bugs:

  • User reports
  • Automated monitoring systems
  • Logging
  • Testing with simulated high load, and/or randomized inputs

The last three I understand, but the first one? I dreaded hearing from customers about problems they have in my projects, I still do. With every report I get, there’s a failure. People pay money to use our products. Customers are not guinea pigs. So I don’t think I’ll skip unit testing, release a crappy product, put my legs up, and wait for my unknowingly beta testers to report the bugs. Might sound interesting, but thank you, no.

So what makes people doubt good practices?

This brings me to Jay’s description of the path to enlightment. People get lost in the process. They don’t fix the painful, they wallow in pain. I’ve seen that also in former employment: In every change to the database, there was a QA person working 2 days to make sure things didn’t break during the upgrade (of course it took more, because they did). And that was repeated  A LOT, like 6-7 times within a 3 month release cycle, for a couple of years. This instead of automating the database testing. This is what Jay’s talking about: we should take the pain out.

So is unit-testing useful? You bet. For many things. But you need to find what works for you, and make it a joy. And for your business sake: don’t let the customers find bugs for you.

Customers are not useful for finding bugs.