Pratik Chorghe
There is a tradeoff between time spent writing tests and code coverage. Some organizations put undue focus on code coverage. Unfortunately, this sets the wrong goal for developers — after a certain point, the returns are not worth the effort. You start seeing developers gaming the system by writing meaningless tests.
Instead, focus on use case coverage. Think of all the use cases (including corner cases) that you want to test to feel confident about your code. This approach will automatically yield high code coverage. The tests in React Test Shop were written with use case coverage in mind and yet as a byproduct, we have upwards of 90% code coverage!
Continuing to build upon the idea of “Test your components as a user would”, a key strategy is to prefer integration testing over unit testing. By integration, we don’t just mean integrating two or more UI components, but also integrating the service layer and API calls. As you know, many of our UI components depend on APIs for displaying and updating data, so exercising the entire chain of components up to the API calls is important.