Skip to content

Test Brittleness

Brittle tests break due to changes unrelated to the behavior they verify - they couple to incidental details and create maintenance burden that discourages both refactoring and testing, ultimately reducing code quality.

Tension Addressed

Sensitivity vs. Stability

Recognizable As

Tests breaking after "safe" refactoring; tests asserting on formatting, ordering, or internal state; tests requiring updates for unrelated changes; high test maintenance cost relative to code changes

Canonical Sources

Feathers, "Working Effectively with Legacy Code" (2004); Fowler, "Refactoring" (1999)

Transfers To

Tight coupling in system design; fragcoupling class problem; change impact analysis

Sources of brittleness: - Testing implementation instead of behavior - Over-specification of mock expectations - Assertions on irrelevant details (whitespace, ordering) - Coupling to internal data structures

Brittle tests impose a tax on change. When every refactoring requires rewriting tests, developers avoid refactoring. The resulting code rot is a second-order effect of test brittleness.