Home › Software Engineering

Write missing unit tests for legacy code

DifficultyMedium
SetupSome code
Best forDeveloper
ToolsClaude Code, OpenAI Codex CLI, Cursor, Aider
The problem

Untested legacy code makes every change risky.

How the agent works

The agent reads a module, writes characterization tests that capture current behavior, runs them, and iterates until they pass, then reports coverage gains.

Setup steps
  1. Pick one module at a time
  2. Ask for tests of current behavior, not desired behavior
  3. Run tests in the loop
  4. Review for meaningless assertions
  5. Commit in small PRs
Tools that can do this
  • Claude Code
  • OpenAI Codex CLI
  • Cursor
  • Aider

Not ranked and not sponsored. Check each vendor's current features and pricing.

Human in the loop

Developer reviews tests.

Risks and guardrails

Agents may write tests that assert bugs; label them as characterization tests.

ROI notes

Makes refactors safer.

Also useful: investigate failures in production logs.