Course contentsShow
← Software Engineering
Lesson 403 of 1,93312. Testing FundamentalsFree lesson

When Not to Test: Diminishing Returns

Some code (trivial getters, framework code, UI layouts) may cost more to test than the value provided.

When Not to Test: Diminishing Returns

What you'll learn: You'll discover when writing tests costs more time and maintenance than the safety they provide.

The Core Idea

Not all code deserves a test. Some code is so simple, stable, or trivial that writing and maintaining tests for it actually slows you down more than it protects you. This is the law of diminishing returns in action: the effort invested stops paying dividends.

Code That Often Isn't Worth Testing

Trivial getters and setters like getName() or setAge(value) rarely break. If they do, other tests will catch it. Testing them directly means maintaining tests that essentially verify your language works.

Framework or library code you don't own shouldn't be tested by you. The framework authors already tested it. Your job is to test your code's interaction with it, not the framework itself.

UI layouts and styling change constantly based on design feedback. Tests for exact pixel positions or color values become maintenance nightmares that break with every visual tweak, providing little confidence about actual functionality.

Generated code from tools you trust is another low-value target. You're testing the generator, not your logic.

The Trade-Off

Think of testing like insurance: you insure your house but not your paperclip collection. The cost of the policy should match the risk and value of what you're protecting. A test that takes 10 minutes to write and 2 minutes to fix every time you refactor, protecting code that takes 30 seconds to verify manually, is a net loss.

Focus your testing energy on complex logic, business rules, and integration points—places where bugs hide and cause real damage.

Key Takeaway: Test code where the risk and complexity justify the maintenance cost; skip tests for trivial, stable, or framework-owned code where the effort exceeds the value.