Tests Are Code — Update Them First on API Change

When an API changes, update its tests before updating its implementation — the tests are the specification, and updating them first forces you to define what the change means before you build it.

What it is

Tests are not annotations on working code — they are executable specifications of what the code is supposed to do. When an API changes, the tests express the new contract. Updating the tests first — before touching the implementation — forces a concrete decision about what the changed API should do, surfaces the callers that will break (because the test updates reveal them), and produces a failing test suite that guides the implementation. The alternative order — change the implementation first, then update the tests to match — allows the implementation to define the spec rather than the spec defining the implementation. This is the primary way that tests accumulate "test drift": the tests describe what the code does, not what it should do, and they never catch the difference. Updating tests first on API change is the same discipline as writing tests before code in TDD, applied to the modify case: the test is the spec, and the spec precedes the build. It also produces a clear commit boundary — "update tests to reflect new API shape" is a reviewable artifact that says what the change is before "update implementation to match new spec" says how the change was made.

When to reach for it

When NOT to

Exemplars

Related