The main trade-off discussed is balancing the cost of testing (time, resources, maintenance) against the risk of not testing enough (potential bugs, downtime, and business impact). The post emphasizes the need to critically evaluate how much testing is necessary and where to focus testing efforts to maximize value.
Refactoring can reduce code coverage percentages because it often results in fewer lines of code. If the same number of tests cover fewer lines, the coverage percentage drops. This creates a paradox where improving code quality by making it more concise can appear to reduce test coverage, even though the code is better.
Aiming for 100% code coverage in a React app with styled components can be problematic because it requires testing every line of CSS. This often leads to low-value tests that don't meaningfully improve code reliability, while consuming significant time and effort that could be better spent on higher-impact testing.
Nicole suggests focusing testing efforts on the most critical parts of the system, such as features that directly impact revenue or user experience. For example, live interaction features that could result in significant financial loss if they fail should be prioritized over less critical features like analysis tools, which can tolerate occasional downtime.
Performance testing is challenging because it must closely match real-world workloads to be meaningful. Simulating realistic user behavior is difficult, especially before deployment, and testing isolated components doesn't capture the non-linear interactions between different parts of the system. Monitoring production behavior can help refine performance tests over time.
Maintaining a large test suite can be costly because it requires ongoing effort to update tests as the codebase evolves. Refactoring becomes more difficult, and the time to run tests increases, which can slow down development workflows. Additionally, tightly coupled unit tests can break frequently during refactoring, adding to maintenance overhead.
Nicole believes a test suite should ideally run in single-digit minutes, with five minutes being the upper limit for a reasonable development workflow. Longer test suites can significantly impact productivity, especially if developers get distracted while waiting for tests to complete.
Nicole uses code coverage to identify and delete unreachable code. By analyzing coverage reports, she can pinpoint code that isn't being executed and remove it, which improves code quality and reduces unnecessary complexity. This approach also helps ensure that the remaining code is well-tested and functional.
Nicole is a software engineer and writer, and recently wrote about the trade-offs we make when deciding which tests to write and how much testing is enough.
We talk about:
Links:
** Learn pytest**