Maintenance cost measures how difficult tests are to understand, change, and run. Readability generally improves with smaller tests, provided code is not compressed artificially; test code deserves the same quality standards as production code. section 4.3
Evaluate maintenance cost through two primary questions:
- Can developers understand and change the test without excessive effort? section 4.3
- Can developers run the test reliably, without maintaining databases, network connections, or other out-of-process dependencies? section 4.3
- Keep most business-scenario edge cases in fast unit tests, while using a smaller number of integration tests for happy paths and cases requiring external systems. section 8.1
- Avoid implementation-specific tests, test-only production code, and special privileges that expose private state; verify observable behavior instead. section 11.8
Figure 8.2. The Test Pyramid represents a trade-off that works best for most applications. Fast, cheap unit tests cover the majority of edge cases, while a smaller number of slow, more expensive integration tests ensure the correctness of the system as a whole.
The Test Pyramid visualizes the maintenance trade-off between many fast, inexpensive unit tests and fewer, slower integration tests. section 8.1
