Engineering Regression Testing Test Generation

Regression Test Prompt — Pin It Before You Change It

Characterization tests for legacy code: assert what it does TODAY — bugs and all — so tomorrow's change can't lie about its impact.

Overview

The most dangerous change is one to untested legacy code: nothing fails because nothing was watching. This setup builds the safety net first — characterization tests that pin current behavior exactly as it is, even where it looks wrong (assert the actual output, flag the suspicious cases), previously-fixed bugs covered by name, and output formats asserted exactly where downstream consumers parse them. The failure scenarios are regression's own: fixed bugs returning, drift in untouched paths, formats changing shape under their consumers.

Workflow

  1. Pin before you plan

    Characterization tests come before the refactor design — you can't protect behavior you haven't recorded.

  2. Assert the weird outputs too

    If it returns a trailing space today, the test asserts the trailing space — and flags it. Consumers may depend on the weirdness.

  3. Name the historical bugs

    Each previously-fixed bug gets a test carrying its ID — the regression suite doubles as the bug museum.

Why This Works

  • Characterization honesty (assert what IS) makes untested code changeable
  • Bug-by-name coverage converts incident history into permanent protection
  • Format pinning protects the integrations nobody remembers exist

Best for

  • Legacy modules about to be changed for the first time in years
  • Code whose only spec is its current behavior
  • Teams that found out about a regression from a customer

Not for

  • Judging whether the legacy code is good — that's the Code Review Prompt Generator's mentoring review
  • Actually refactoring it — pin first, then the Refactor Prompt Builder

Use cases

  • Building a safety net before refactoring a legacy module
  • Pinning output formats that downstream systems parse
  • Covering historical bugs so they can't quietly return

Tip: Save time by exploring related resources and tools that integrate with this workflow.

Explore all resources