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.

How to use this resource

  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

FAQ

Why does this prompt tell the AI to assert buggy output instead of the correct output?

Because characterization tests pin what the code does today, not what it should do. The TEST STRATEGY says to "assert actual current output, even where it looks wrong, and flag the suspicious cases" — a trailing space today gets asserted and flagged, since a downstream consumer may depend on it. The test-case-prompt-generator outputs these tests; you run and review them.

How does this prompt keep a fixed bug from silently coming back after a refactor?

The COVERAGE AREAS require previously-fixed bugs "covered by name, one test each," and the FAILURE SCENARIOS explicitly include "a previously-fixed bug reappears after a refactor." You supply the historical behavior; the generated tests name each bug so a failure message identifies the regression. The tests protect behavior, they don't guarantee correctness.

Will the generated tests be locked to pytest or JUnit?

It doesn't. FRAMEWORK GUIDANCE is set to Generic, so it uses "the project's existing test framework and follows its established conventions" rather than imposing one. For a specific framework's idioms, regenerate in the test-case-prompt-generator with that framework selected. Either way it returns one runnable file grouped by coverage area, not code you've confirmed runs.

More resources from Test Case Prompt Generator

Resources that pair well

Related tools

Workflows that use this resource

Guides for this resource

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