TestingScroll #011

Mock what you must. Understand what you mock.

Every substitute encodes assumptions about a dependency that may drift from reality.

All scrolls

Interpretation

Mocks buy speed and isolation by replacing reality with a model. If the model omits latency, errors, serialization, or version behavior, a green test can defend a fiction. Use substitutes at deliberate boundaries and verify the contract against the real dependency often enough to keep it honest.

Practice

  • Mock at stable boundaries rather than every method.
  • Run contract tests against real implementations.
  • Model meaningful failure modes in substitutes.

Anti-pattern

A mock returning values the real service can never produce.