AI USE CASES YOU CAN REUSE.English edition · Individuals, independents, small businesses
Practical case

Write characterization tests before refactoring an old code

Scenario written by the desk, with a prompt to adapt. This is not a testimony.

The result to aim for

Before touching an old module, have an agent write tests that freeze his current behavior, to refactor without breaking.

The situation

The code inherited without testing is the riskiest to change. The method of characterization tests is to capture what the code does today, including its bizarreness, before transforming it. A code agent is effective in writing these tests in mass; Human decides which behaviors are bugs.

Before you start

Tool cited: Codex; the prompt also works with Claude Code and GitHub Copilot. Fill in the bracketed items: [chemin], [préciser]. Strip confidential data that is not needed and check your tool’s access terms. Features and plans can change.

The method, in three steps.

  1. Gather the context

    Spot the bracketed items in the prompt ([chemin], [préciser]) and prepare what they ask for.

  2. Adapt the prompt

    Copy the prompt below, replace the bracketed items, then paste it into Codex, Claude Code or GitHub Copilot.

  3. Reread before using

    Reread the result, correct it if needed and keep the final decision. Caveats are detailed below.

Your starting point.

Replace the bracketed items, then adapt the proposal to your situation. This prompt is written by the iadujour desk.

The prompt to customise
Refactoring module: [chemin]. Test language and framework: [préciser].

1. Read the module and list its observable behaviors (inputs, outputs, onboard effects).
2. Write characterization tests that freeze current behavior, including limit cases. Do not change the module code.
3. Run the tests and show the result.
4. List separately behaviors that look like bugs, for human decision.
Only then, proposes a small step refactoring plan.

What deserves your attention

A test that freezes a bug is not a validation: note apart from suspicious behaviors.
Origin of the case. Scenario designed by the iadujour.fr desk, written in November 2026.
Proof level: Practical case written by the desk, no third-party source. This is not a testimony: adapt the prompt to your situation.

Useful skills

Official skills on the same task, paired by the desk: they are not part of the described case.

  • Build an application with SDK GitHub CopilotMicrosoft · Guides the creation of applications that rely on GitHub Copilot via the Copilot SDK, for programmatic integrations in Node.js/TypeScript, Python, Go or .NET: sessions, custom tools, streaming, hooks, MCP servers, BYOK providers, persistence, agents and skills, and deployment schemes.
  • Create an MCP server and widgets for Copilot ChatMicrosoft · To build MCP servers for Copilot Chat, with widgets rendering (OpenAI Apps SDK or MCP Apps SDK, any language), including React and Fluent UI widgets and tools that return structuredContent.
  • Create a reporting agent M365 Copilot or TeamsMicrosoft · Creates, assembles, deploys, and locates reporting agents for M365 Copilot and Teams: scaffolding, editing demonstrations, adding capabilities or plugins.
TO GO FURTHER

Other ideas to put to work.

The whole Dev theme
Dev

Make a pull request by an agent before the human review

A first automated passage to identify probable bugs, missing tests and safety risks, so that the human review focuses on the essentials.

Tool: Claude CodeType: Practical case
DISCUSSION

Comments.

A field note, a question, a precision on this use case? Comments are reviewed before publication.

Published comments

Loading comments…

    Leave a comment

    Moderation charter. Every comment is reviewed before publication. We refuse hate speech, insulting or discriminatory language, advertising, spam and promotional links, off-topic posts and other people’s personal data.