Guide

How to test code written by Cursor

Cursor's agent will write tests, run them when it knows the command, and keep going until they pass. That speed is the point of using it. It is also how a session can grade its own work. This page is the Cursor setup: put the real test commands in project rules or AGENTS.md, enforce them with hooks.json, review the pull request with a fresh pair of eyes, then confirm the tests would fail if the new code were wrong.

The same method works in Claude Code, Codex and GitHub Copilot. A combined walkthrough is in How to test code written by Claude Code or Cursor.

Put commands in rules or AGENTS.md

Cursor reads project rules and, where you use them, AGENTS.md. Tell it which test command is the real one, which tests need a database, and how to run a single file. Keep it short and concrete.

## How to check work in this repo
- Typecheck: pnpm tsc --noEmit
- Unit tests: pnpm vitest run
- One file: pnpm vitest run path/to/file.test.ts
- Integration tests need DATABASE_URL (see .env.example)
- Never edit snapshot files to make a test pass. Ask first.

For a behavior change, ask Cursor to write a failing test, show the failure, then fix the code and show the same test passing. Ask it to paste the commands and output, not a one-line summary.

Enforce checks with hooks.json

Rules are suggestions. Hooks run every time. Put a hooks.json in .cursor/ at the project root. afterFileEdit runs after the agent edits a file, and stop runs when the agent finishes. Project hooks also run in Cursor cloud agents. Cursor can load Claude Code hooks for compatibility. Exit code 2 from a command hook blocks the action.

{
  "version": 1,
  "hooks": {
    "afterFileEdit": [{ "command": ".cursor/hooks/format.sh" }],
    "stop": [{ "command": ".cursor/hooks/check.sh", "loop_limit": 5 }]
  }
}

Review with Bugbot or a fresh diff

Cursor Bugbot reviews pull request diffs for bugs, security and quality issues, runs on PR updates, and publishes a Cursor Bugbot check. Findings default to a neutral status, and teams can configure unresolved findings to fail the check. Use that, or another reviewer, so the first agent is not also the only reader of the diff.

Prove the tests catch a break

A passing hook and a Bugbot comment still do not prove that your tests would catch a real fault in the new behavior. OrangePro is a local MCP server that ranks weak test evidence and can show whether a test catches a break. Add it in ~/.cursor/mcp.json or in Cursor Settings, MCP. Run it after Cursor's tests are green, before you treat the change as protected.

{
  "mcpServers": {
    "orangepro-local": {
      "command": "npx",
      "args": ["-y", "@orangepro/mcp-server@latest", "mcp"]
    }
  }
}

Or print a Cursor-specific snippet with npx -y @orangepro/mcp-server@latest agent --client cursor. Mapping, ranking and proof stay on your machine.

Frequently asked questions

Add a project hooks.json in .cursor/ with a stop hook that runs your test command, and an afterFileEdit hook for formatting or fast checks. Exit code 2 from a command hook blocks the action.

No. Bugbot reviews the diff and can fail a check when findings are unresolved. It does not execute your tests or prove they would fail if the new code were wrong.

Yes. Add the local MCP server in ~/.cursor/mcp.json or Cursor Settings, MCP, then ask for unprotected functions or proof that a test catches a break. Local runs do not upload your source.

No for mapping, ranking and proof. Drafting tests with real assertions uses a model provider you choose, with your own key, called directly from your machine.

Try it on your code

Add the local MCP server to Cursor and ask for the top unprotected function. Local runs do not upload your source.

$npx -y @orangepro/mcp-server@latest agent --client cursor

Built for after merge, before release. It is not a pull request or release gate. Local scans do not upload source.