100% UT coverage is not a luxury but a necessity.

Don't spend time in deciding on the UT coverage thresholds. Make it 100% and spend that time in writing tests.

Any team needs to ensure their codebases are maintainable, scalable, and frequently updated against the best practices, code quality, and security aspects. If a new engineer joins, they need to appreciate the codebase as they own it. But, this is far easier said than done.

I work in a very large organization. This comes with its own problems. People never stay in the same team for longer. Mostly the floating population of engineers maintain the codebases and work with them. A year from now, the engineers who write the code today will be long gone. It’s then up to the new engineers who join the team to pick up the existing mess and build their own mess on top of that.

This makes it all the more important to have a maintainable, high-quality codebase.

Please please please, at least have 100% Unit test coverage for the codebases. This at least makes things a bit easier for the newer engineers when they think of refactoring or improving the codebases.

When it comes to the front end, I understand that with 100% coverage, we don’t guarantee all the scenarios are tested as they could be invoked from different async flows. That’s where the use case testing like RTL (React Testing Library) comes into play. 100% coverage at least guarantees that all the lines, branches, and other coverage are tested perfectly.

I’ve seen teams come up with their own magic thresholds like 85%, 90% , 95% for their UT coverages. I cannot insist enough on the fact that Unit Tests must always be 100%. Saying 85% UT coverage is like saying 15% of the flows in my production I don’t care to test. This is immature.

Ok, enough with the ranting. Let’s find some benefits of maintaining a 100% UT coverage:

  1. Bug Detection: Comprehensive coverage helps catch bugs early in development, ensuring a higher-quality codebase. It aids in identifying issues before they reach production.

  2. Refactoring Confidence: With a robust suite of unit tests, developers can refactor code confidently, knowing that if any functionality breaks, the tests will highlight it.

  3. Code Stability: UT coverage promotes stable code by ensuring that changes in one part of the codebase don't inadvertently impact other areas.

  4. Improved Collaboration: Tests serve as documentation, facilitating collaboration among team members. New developers can understand functionality by looking at tests.

  5. Enhanced Maintainability: As the codebase grows, having extensive unit tests makes it easier to maintain and update the code without introducing regressions.

  6. Faster Development Cycles: Catching bugs early and having the confidence to refactor leads to quicker development cycles, saving time and effort in the long run.

  7. Reduced Technical Debt: Comprehensive tests prevent the accumulation of technical debt by encouraging clean, modular, and easily maintainable code.

  8. Increased Confidence in Releases: Teams can release new features or updates with higher confidence, knowing that a strong test suite backs the changes.

  9. Better Understanding of Requirements: Writing tests often involves understanding the requirements deeply, ensuring better alignment with user needs.

  10. Cost Savings: Catching and fixing bugs early in the development process is more cost-effective than addressing them later in production.

For a Senior Frontend Architect/Engineer like yourself, maintaining a high (100%) UT coverage aligns with your expertise in ensuring performance and reliability in large-scale projects. It complements your focus on frontend performance, latency, and advanced aspects by providing a solid foundation for stable and maintainable code.

Reply

or to participate.