Ask a Developer: Code Coverage Uncovered
Have a development question and can’t find the answer? In our Ask a Dev column, a developer from Sentry will answer your questions about languages, frameworks, testing, performance monitoring, or whatever topic is on your mind. To submit a question, email firstname.lastname@example.org.
Question: I find it impossible to stick to a high code coverage metric when testing my app. Do companies actually bother with this?
A: One of the major pitfalls we see folks fall into is the “100% tested code or bust” mentality. There are benefits to having 100% code coverage, but it’s important to keep in mind that achieving complete coverage may not always be possible or practical, even in larger organizations. To put this into context, we find that only about 22% of repos using Codecov have actually achieved the 100% mark. The majority of Codecov users are above 80% coverage.
In such cases, it may be better to focus on testing critical or high-risk areas of the application and the quality of your tests to see the value and return on investment.
Organizations that care about having a well-tested, resilient code base really depend on code coverage, and there’s a clear metric to show the value as the earlier you catch/prevent a defect, the “cheaper” it is for your organization to patch that error. I think we can all agree that it’s far, far better for a developer to catch a bug while writing the code than a customer to catch it for you in production no matter the size of your organization.