DEV Community

Evelyn Bauer
Evelyn Bauer

Posted on

5 simple reasons why testing code is important

Image description

It is not news that testing code is essential for a project. Nowadays, with the need for development cycles to spin faster and code to be frequently pushed to production, testing code is crucial to avoid problems in production. This article suggests 5 simple reasons why testing code is important to help reinforce the testing habit.

🙅‍♀️ THE AVERSION EFFECT: IS TESTING REALLY PAINFUL?

For some developers, testing can be considered painful due to the lack of time, knowledge or clarity in terms of what should be tested. Some might as well say that testing is a QA's job, however, not all companies have the luxury of hiring a QA professional. Testing can be frustrating whether you're about to start a project or you need to implement them to an old and complex project. In both situations, testing needs to be interpreted as a process that takes time and will benefit the product, the company, and the whole team in the long run.

SHIPPING UNTESTED CODE: A TICKING BOMB! 💣

With so many interesting tools and testing suites available out there, there are not good enough excuses to ship untested code. By pushing untested code to production, not only the developer who wrote the untested code but, the entire team is signing off the damages it can cause. Shipping untested code is dangerous! As soon as it hits production is just a matter of time until a bomb explodes.

5 SIMPLE REASONS WHY YOU SHOULD TEST YOUR CODE

Let's be honest, there are much more than 5 simple reasons why testing code can be beneficial. However, 5 of them are good enough to help developers judgement to ship untested code to production. The decision of pushing untested code can be made in a split second, the results can go from success to a big disaster depending on it.

1. Better performance:

From a user's prospect, there is nothing worst than dealing with a non-performant product. By setting some rules on tests, developers can prevent insane conditions from hitting production and causing poor performance. For example: if the user is searching for something and there are 10.000 possibilities, it is not performant to show the 10.000 options at once. In this case, setting a limit on a test would help to prevent the 10.000 options from being rendered. If the limit is hit when the test runs, the developer still has time to work on solutions and manage disasters in advance.

2. Code quality:

Writing tests can improve code quality in many ways. The simplest way to realize that is when writing a test for the code a developer just wrote. If writing the test is complicated it means the code is too complex. The tests can make developers aware of code complexity and sometimes when a code could be cleaned/improved/refactored.

3. Code coverage:

It is pretty hard to achieve 100% code coverage. However, what matters is not the total project's coverage percentage but, making sure the lines of code and files being shipped to production are being properly tested. It is better to guarantee that the new changes being shipped are tested than to waste hours debugging problems later.

4. Routine & Confidence:

Writing tests on a daily basis triggers an unconscious process. At some point, writing code can make developers think about what the test will look like and writing the test can make them aware of possible improvements in the code. It is a way to achieve better code quality and confidence naturally.

5. Review final product:

Here is where the famous proverb "Better safe than sorry" makes all sense. Running tests before pushing new code to production is the perfect opportunity to test the final product before making it available for clients. More importantly, it ensures customers won't find bugs that can be caught in the first place.

💁‍♀️ LOOKING FOR AN EXTRA REASON?

Jokes apart, testing code can improve devs work-life balance. By testing code, it is possible to reduce all the stress bugs and fires that untested code can cause/reveal in production. Thanks to tests, chances are that devs won't need to wake up in the middle of the night because an entire app went down.

The reasons why writing code is important are endless but, keeping in mind some of them, makes the testing process more organic and meaningful. Tests have the power to improve a project, help developers to become better developers and get the work-life balance that sometimes gets lost among bugs, fires and chaos caused by unhealthy code. Next time someone tries to push untested code to production, just remember the simple reasons!

Top comments (0)