Structure-Insensitive Tests
A behavior-preserving refactor should not change any test’s result. The mirror of Behavioral: that one asks tests to notice what matters, this one asks them to ignore what doesn’t. Tests coupled to names, call sequences, or private structure turn every refactor into test surgery; Fowler’s refactoring safety net only works when the net doesn’t move with the code.
Planted as a seedling on purpose: this is the one Beck property the research behind Test Desiderata has not yet put through a cross-author audit. It stays on the strength of the refactoring literature until then.
It pulls against two other properties. A test that ignores internals fails over a broad surface, so it localizes the defect worse than a Diagnosable one would; and the easy way to make a test cheap to write, mocking collaborators, is exactly what couples it to structure. Both are trade-offs among the properties.
Part of Test Desiderata.
Measuring: refactor-safety rate. Green stays green through a behavior-preserving refactor.
Sources
- Martin Fowler, DefinitionOfRefactoring: refactoring as behavior-preserving change.
- Martin Fowler, Workflows of Refactoring: refactoring proceeds on a green test suite, the safety net that lets you change structure freely.