liveBook · Manning

Maintenance cost

As explained in Unit Testing Principles, Practices, and Patterns

A metric that measures how easy tests are to understand, change, and run and the maintenance effort they require.

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

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Explains two maintenance-cost components and connects them to test sizing, dependencies, test ratios, and black-box boundaries.
Examples
Uses test size, external dependencies, test ratios, private-state exposure, and test-only production code as concrete indicators.
What you can do after
Evaluate tests by balancing readability, operational effort, regression protection, and observable behavior.
How it connects
Connects maintenance cost with unit testing, integration testing, the Test Pyramid, refactoring, black-box testing, and code pollution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.