The true value of unit testing.

2 Responses

  1. Larry Hengen says:

    I agree with you whole heartedly!

    Units test are most useful to mitigate breakage as the code is modified after release, because finding bugs, fixing them, and getting them out to your customers before those bugs cause havoc is time which is money. Releasing bugs affects your credibility and that’s even harder to fix afterwards.

    Unit tests serve as great documentation on how to use your APIs and force you to think like a tester, covering edge cases.

    You are 100% correct that even if you wrote it a week ago, you probably don’t remember all the nuances of the code and can modify it without any breakage. Besides that everyone has bad days..

    The biggest reason that XP has not been adopted is that businesses have not accepted all the studies that show unit testing pays for itself in the long term. Businesses are in it for the short term as products quickly become “obsolete” and want to quickly get them to market. As a result, sometimes building unit tests is very difficult as the initial design does not lend itself to testing since that was not a consideration up front.

    I worked for a company where I wrote tests that got broken, and the senior lead developer simply ignored the fact until 3 months later when a customer complained. Even afterwards he questioned the value of unit tests. It was hard to convince both management and the dev team that unit tests would pay for themselves especially since the product has been around a long time already. Unfortunately, I have lots of similar experiences. People in the industry since it’s inception tend to look at all the great products created without unit testing, and think it isn’t necessary.

    • Absolutely.
      I once worked on a maintenance team fixing bugs. One bug came in which I repaired, but my repair damaged another part of the app. Another engineer repaired his use case, which re-opened my issue. We bounced back and forth perhaps three times each fixing our own use case, unaware of the other before we realized. Had that company had a policy to put a test in place for bugs, neither of us could have reopened the others bug, because the test suite would have caught it.

      Engineers aren’t cheap, as you’ll be aware, the highest cost to any business is staff, and so if we each spend one-two hours per case, you could calculate the cost to the business. I’ve done this math before, and not wanting to mention numbers, an hour to write a unit test would have been cheaper. I feel as professionals, we should illustrate such cases to the business as it’s simply wasteful.

      Thanks for sharing your experiences!

Leave a Reply