Convincing the Customer to write unit-tests

Benefits of unit testing

short overview of the major benefits:

  • Reduce the Number of Bugs - Many developers have to deal with bugs in production code. Taking care of it, is not only tedious and time-consuming, but issues that appear in production are much more complex than if they’d have been discovered in development or staging. By adding unit tests to the work routine, failure can be detected early on, pretty much as soon as the code is written, and the development team will be able to take care of any unintended effect pretty much from the beginning without major complications. If you consider yourself Agile, unit testing is part of your work.

  • Easily Change and Refactor Code - Automated unit tests can catch bugs easily, and knowing that makes you feel more confident. Once an issue is detected, you feel more at ease when you have to make changes to your code, even if the changes are beyond trivial ones – any code issue detected before it’s released to production is a victory!

  • Automated Tests - We run tests, so we can predict the outcome and make sure our code will work once delivered – even if it becomes ‘legacy’. Manual tests can only go so far, and that’s when automated tests come into the picture. Automated tests are fast, allow us to run tests as frequently as required, even if we are busy with other tasks. Once written, it can be used as often you need it. If the code is changed later, these tests can point to problems without additional effort.

  • Improve Code design - Unit testing can improve code design, especially in test-driven developments (TDD). This is a topic in its own right, but when you consider implementing unit testing, you have to make sure that your code is testable. Think about it, when you deal with the overall design concept, and you need break down the high-level design to ‘single entity-multiple components’, you’ll be forced to think of each unit and make sure each of them is testable. This improves the overall code design by clear unit separation, defining better unit interfaces and the design concept.

  • Unit tests are a Form of Documentation - Even if you don’t document your code but you unit test, you provide documentation of the system when you test. Unit tests fix the software’s behavior – and only pass if the software works as intended. Developers looking to find out what functionality is provided by a unit, only need to look at a test and can conclude how the unit is supposed to work. It’s a huge benefit for us developers to understand the thought behind the code, even when it comes to your own code. After a few months you might forget why you wrote it like that.

  • Unit Testing Improves Teamwork - Another gain of unit testing, as well as documentation, is that it improves teamwork. Your colleagues can review the logic behind your code and coordinate their code accordingly. Being able to review each other’s code, the teamwork is more cohesive and Agile.

  • Unit Testing Inspires Confidence - You develop software and then you write tests to examine if it works. You will be able to validate in the early stages whether your code is actually functional. Once your tests are passed, you feel confident knowing that your software is in good shape. Many issues can be avoided this way (although not all). Knowing that your code is legit gives you a good

  • Reduce Costs- Since the bugs are found early, unit testing helps reduce the cost of bug fixes. Just imagine the cost of a bug found during the later stages of development, like during system testing or during acceptance testing. Of course, bugs detected earlier are easier to fix because bugs detected later are usually the result of many changes, and you don’t really know which one caused the bug.

Strategies

Show the Return On Investment (ROI)

Writing automated tests takes time. Once. Running automated tests takes zero time, because you can do something else while they're running.

Example: Manually testing feature X takes 30 minutes. Writing an automated test for it would take 1 hour. Even if we have no bugs, we will have to test feature X ten times during the course of the project as its dependent layers and components are modified. So automating the test of feature X will save us 4 hours over the life of the project.

In reality, it's when you have a bug that automated tests really pay off - First, they find bugs early and cheaply, which saves time and embarrassment. Second, if you have a difficult bug and go through many cycles of code-build-test to figure it out, the time saved over manual testing adds up extraordinarily fast.

Businesses understand saving time and money. That's how to sell it.

Write tests after the bug

For every customer-facing production issues:

  1. Write a Unit test and send an email to the manager saying that You have added a Unit test to cover the scenario.

  2. And tell him that This issue will not happen again in production because our unit test is running nightly and we will come to know before the code goes to production by watching this unit test failure.

  3. Tell him that if we already had this Unit test in place before the code went to production, this production issue would never have happened.

Do this consistently and persistently and soon he will be convinced. Managers do not like the customer-facing production issues and he will buy into the Unit testing idea.

Last updated

Was this helpful?