Make Each Characterization Test Fail Once Before You Refactor
Описание и применение
Тесты, которые никогда не падают, не защищают от скрытых изменений. Внедряя временные «швы» в тестах, фиксируя поведение и проверяя, что тест падает при намеренном изменении, можно безопасно рефакторить код.
Задача
Refactoring messy code often leaves tests that never fail, masking silent behavior changes.
Результат
Tests now assert on observable behavior and side‑effects, ensuring refactors cannot silently alter functionality.
Рабочий процесс
- Inject temporary test harness seams to control randomness, time, network, and global writers.
- Capture the function’s behavior (including side‑effects) into a snapshot and write goldens to disk.
- Commit the goldens so they can be diffed and reviewed.
- For each case, deliberately mutate the code under test and confirm the test fails.
- Only after a failure is observed, make the smallest safe change and re‑run the test.
- Repeat until all cases survive one intentional mutation.
Доказательства
A test only earns trust when you can make it fail on purpose.
Write goldens to disk. Commit them. A reviewable diff beats a magic assertion.
- Дата записи: 2026-09-20T05:45:17.593Z