DEV Community

k1940
k1940

Posted on

In what situation you feel like writing tests in react is critical?

I have been writing react for 4 years in different scales and types of applications. I have never run into a situation where I really feel the need to write tests. Is writing test still a thing?

Top comments (3)

Collapse
 
ingosteinke profile image
Ingo Steinke

As a senior developer, I can confirm that, despite most of us have been guilty of writing and deploying untested code, writing tests is still a thing. Or rather, testing should be a thing. If you don't like writing tests, you might want to generate tests or outsource much of the testing to other team mates or services providers.

Test your own code! Test all of your own code, if you can. This includes legacy code by team mates. Write unit tests when you focus on business logic. Go for end-to-end, behavioral, and front-end testing, including design system mock-ups (storybook, storyshots) and screenshot diffs.

You don't test third party libraries, instead you choose libraries that are well-tested and maintained. So if you use a lot of libraries and simple boilerplate code, there might not be that much to test after all.

Sooner or later, you will eventually run into a critical situation where tests (or more tests, or more intelligently conceived tests) would have saved you (or your customers). And then you will also see the rest of your codebase with different eyes.

So back to the happy situation where you don't feel the benefits yet and you might not feel comfortable with what and how to test either. There are a lot of great frameworks, tutorials, and services to assist you.

Some suggestions can be found in my blog post about automating tests using CodeceptJS and Testomat.io

Collapse
 
kayden1940 profile image
k1940

Thank you very much for the perspective. I can imagine with a large team of developers mantaining a legacy, large scale applications would have the need of unit testing. I once mantained such application but didn't get enough time to think of unit testing.

Collapse
 
brense profile image
Rense Bakker

You should write tests when a lot (10+?) of other developers are going to use/change your code. Though it depends a lot on the business requirements as well. Some companies are more functionally focussed and they might benefit from unit tests. Other companies are more visual focussed and they might benefit from e2e tests.