Home › Browse

Write unit tests: how to do it with AI

Last checked 2026-10-15

IntermediateBot with human review 💻 Coding

Generate tests for existing code and run them in an agent.

1. Bot automation level

Bot with human review The bot does the work, but facts, numbers or code should be checked.

2. Before you hand it to the bot

3. Copy-paste prompts

Main prompt
Read <module>. First list the test cases you plan (happy path, boundaries, errors). Wait for my OK, then write <framework> tests and run them. Don't change source code.
Beginner-friendly
Read <module>. First list the test cases you plan (happy path, boundaries, errors). Wait for my OK, then write <framework> tests and run them. Don't change source code.

I'm new to this: explain each step in plain words and ask me for anything you need before starting.
Check-your-work
Read <module>. First list the test cases you plan (happy path, boundaries, errors). Wait for my OK, then write <framework> tests and run them. Don't change source code.

When you finish, list any assumptions you made, anything you're unsure about, and what I should double-check before using the result.

Free tiers that can handle this (verified): ChatGPT (incl. Work & Codex), GitHub Copilot, Mistral Le Chat. Others: check plan.

4. Step-by-step

  1. Choose the framework (pytest, Jest, JUnit) and tell the agent which one.
  2. In an agent (Claude Code, Cursor Agent, Codex, Copilot agent mode) ask it to read the module and list cases before writing tests.
  3. Approve the case list: happy path, boundaries, error paths, mocks for I/O.
  4. Let the agent write the tests and run them in the terminal.
  5. If tests fail, decide whether the test or the code is wrong — don't let the agent 'fix' code to match a wrong test.
  6. Check coverage locally and commit on a branch.

5. Which bots and plans can do it

ToolWhat's different herePlan limitsSource
Claude (incl. Claude Code)Claude Code runs commands in your terminal with permission prompts.Claude Code and Research need Pro or higher; computer use is Pro/Max only (research preview).code.claude.com/docs/en/desktop
ChatGPT (incl. Work & Codex)Codex runs tests and commands locally or in cloud environments.Free tier has limited deep research, Codex and Work; scheduled tasks need Go or higher (per chatgpt.com/pricing).help.openai.com/en/articles/20001275-chatgpt-work-and-codex
CursorAgent can run terminal commands to execute the tests.Pricing page unverified; cloud agents require a connected source-control repo.cursor.com/docs/agent/overview
GitHub CopilotAgent mode in your IDE edits files locally; the cloud agent works in GitHub Actions.Free: 2,000 completions + 50 chats; cloud agent listed on paid plans.docs.github.com/en/copilot/concepts/agents/cloud-agent/about-cloud-agent
Mistral Le Chat—Free tier has limited messages, searches and coding sessions; Pro raises limits.mistral.ai/pricing
DeepSeek—Chat app limits not documented officially; API is pay-per-token.api-docs.deepseek.com/quick_start/pricing

Free or paid?

6. Risks and what to double-check

Professions that use this

Software developer

Related tasks

Open in the interactive app