In the pack: ChatGPT, Claude & Gemini Prompts for Coding and Developers
Characterization Tests for Untested Legacy Code
Prompt
Language and test framework: {{LANGUAGE}} / {{TEST_FRAMEWORK}}
Legacy code: {{LEGACY_CODE}}
Its dependencies (database, network, clock, files, globals): {{DEPENDENCIES}}
Do this:
1. Find the seams: places where you can control inputs and observe outputs without changing behavior (parameters, injectable dependencies, overridable methods, environment variables). If there are none, suggest the smallest safe change that creates one, and label it clearly as a code change.
2. Choose inputs that exercise each branch. List them in a table with the branch each one reaches.
3. Write the tests so they record current behavior. Where you can't determine the output by reading the code, leave a clear placeholder and tell me to fill it by running the code once (the "golden master" approach).
4. Control non-determinism: freeze the clock, seed randomness, and stub network calls.
5. Mark any behavior that looks like a bug with a comment, but test the current behavior anyway.
Don't refactor the code under test. The point is to capture it as it is.
Customize this prompt
Fill in the variables below to personalize this prompt:
Model Settings
Recommended Models
Temperature
Max Tokens
Additional Notes
About this prompt
“Characterization Tests for Untested Legacy Code” is a free prompt for ChatGPT in the Coding & Software category, 198 words long, added to The Prompt Index on October 28, 2026 by The Prompt Index. Copy it with the button above, paste it into ChatGPT or any other AI chat assistant, and send it.
It has 4 placeholders to fill in first:
{{LANGUAGE}}, {{TEST_FRAMEWORK}}, {{LEGACY_CODE}}, {{DEPENDENCIES}}.
Use the “Customize this prompt” fields to personalise it before you copy.
Recommended models: ChatGPT, Claude, Gemini.
0 upvotes, sent to an AI tool 0 times, viewed 3 times.
Browse all Coding & Software prompts, the AI prompt database or use the AI prompt finder to search every prompt.