How important is testing for a React developer?


A common question to have when we're starting to learn React is how important it is to know how to write automated tests.

To understand how important automated tests can be, we first need to know why we write them.

Why automated tests

We write automated tests because we expect them to save us money, time, or both.

How much money and time automated tests will save us depends on the context we're working on. The domain of the application, the number of people working on the team, and the size of the codebase, alongside other things, influence how useful automated tests can be. Therefore, how important it is to know how to write automated tests will depend on the project's characteristics.

Where automated tests aren't important

There are several ways automated tests can save time and money. Some of them are: Reduce manual testing time. Prevent regression bugs. Give feedback on the modularity of the codebase, which can be used to make it easier to maintain.

If we're using React to work on projects where none of the issues addressed by automated tests exist, not knowing how to make them isn't a problem. Simple blogs, portfolios, and landing pages tend to fit this category. We can manually test them quickly, and they usually don't get new functionalities or benefit from activities such as refactoring. I'd even say that for projects of this nature, writing automated tests might be detrimental as the cost of creating and maintaining them may surpass the benefits.

Where automated tests make all the difference

Automated tests can make a significant difference in projects that will continuously get new features, have multiple people working on it, and long term maintainability is a real concern. Which if we're working on a company with a React-based product will be the case most of the time.

As the project starts to grow and more people begin to work on it, not everyone will know every corner of the codebase. And that together with how much frontends tend to change, the probability that someone introduces a regression skyrockets.

Manual testing becomes prohibitively expensive as the number of logic branches only increases. And that's not to mention how mind-numbingly boring manual testing can become when we need to test for quirky browsers like Safari.

The codebase design starts to matter, as it is hard to add new features or change existing ones in a poorly designed application, thus reducing the maintainability of the project.

These are all issues that cost us time and money, and that automated tests can help us with. This is not to say that automated tests are the definitive cure for all software problems, far from it. But it can make such a difference that some companies won't accept developers that don't know how to write automated tests.

Conclusion

In summary, the importance of automated tests depends on the characteristics of each project.

If we only work on projects where automated tests won't save us money or time, learning how to do them might be unnecessary.

However, on complex applications with multiple people working on it, automated tests can make such a difference that we might not even be allowed to work on the project if we don't write automated tests for what we develop.

Other articles about testing

If you enjoyed this article, you might also like the following:

  1. How to get started testing React applications
  2. Don't know what to test on your React App? Learn how to make a test list.
  3. Not sure how to write tests for your React app? This might help.