Skip to content

Test and debug with Cursor

Testing and debugging with Cursor is a three-guide section for developers who let Cursor’s agent write tests and fix bugs. The guides cover writing the failing test first, generating tests that catch real bugs in existing code, and finding a root cause before any fix. Each one ends with evidence a reviewer checks instead of reading the diff.

You asked Cursor’s agent for tests on a payment service. It wrote 30, every one passed, and coverage jumped. A week later a refactor broke refunds and not one test went red, because the tests asserted what the code already did, not what it should do. This section is for the developer who writes those prompts and the tech lead who decides what a test-bearing pull request must prove.

Your situationStart withYou leave with
New feature or behaviour changeTest-driven development in CursorA failing test written from the spec, then an implementation that turns it green
Existing code with few or weak testsTesting patternsCharacterization tests, coverage for real edge cases, and test data factories
Something is broken, often intermittentlyAI-assisted debugging in CursorA reproduction, a proven root cause, and a regression test that failed first

Prerequisites: a working agent setup and a test command the agent can run (Cursor quick start, project rules).

How the test-and-debug loop runs in Cursor

Section titled “How the test-and-debug loop runs in Cursor”

All three guides share one order, and the order stops the agent from writing tests that fit its own code.

  1. Specify the behaviour in Plan Mode. Plan Mode “creates detailed implementation plans before writing any code”. Turn the request or bug report into acceptance criteria, with no edits.

  2. Write the test and watch it fail. Cursor’s agent writes tests only; source files are off limits. A test that passes before the change exists tests nothing.

  3. Implement with the tests locked. The agent changes source files until the suite is green, and does not edit the tests. Commit first so git diff --stat shows what it touched. An instruction is not a lock; enforce it with a CI check that fails when the implementation commit touches tests/ (protect the oracle).

  4. Run every gate. The full test suite, the type check and the linter, locally and in CI.

  5. Get an independent review. Bugbot or a second agent reviews the pull request against the acceptance criteria, not the agent’s own summary.

How do you trust agent-written tests without reading them all?

Section titled “How do you trust agent-written tests without reading them all?”

Check that the tests can fail and that nobody bent them to fit the code. Require this on every pull request that adds or changes tests:

  • Red before green. Each new test fails on the old code, and the failing output goes into the pull request.
  • Break-it check. The second prompt above: a test that survives a deliberately broken line is decoration. Oracle strength explains how to measure this across a suite.
  • Tests untouched during the fix. git diff --stat for the implementation commit lists no test files.
  • Gates green in CI, not only in the agent’s report.

The developer owns the evidence. The reviewer approves when every item is present and reads code only where an item is missing or surprising. The reasoning is in reading evidence instead of code.

For UI bugs and end-to-end checks, the official Playwright MCP server (@playwright/mcp 0.0.82, checked with npm view on 26 September 2026) lets the agent drive a real browser and read console errors. Add it to Cursor’s MCP configuration (mcp.json; see MCP setup):

{ "mcpServers": { "playwright": { "command": "npx", "args": ["@playwright/mcp@latest"] } } }

Add --isolated to args when several agents test in parallel, because a persistent browser profile opens in only one browser at a time. Tool schemas and page snapshots cost context, so enable the server for UI work only. Alternatives are compared in Playwright MCP and testing and debugging skills.

What goes wrong with testing and debugging in Cursor?

Section titled “What goes wrong with testing and debugging in Cursor?”
SymptomLikely causeRecovery
All new tests pass on the first runThey were derived from the implementationRerun the first prompt with the rules stated and src/ read-only
A failing test turns green after an edit to the testThe agent changed the assertion to fit the codeRevert the test, say “The test is correct; fix the implementation”, and check git diff --stat
Each fix breaks something elseThe agent edited before the cause was knownRestore the last clean commit and return to Plan Mode (bug hunting)
Coverage rises, bugs still escapeTests exercise lines without asserting outcomesRun the break-it prompt on the module that leaked the bug
Green locally, red in CIDifferent data, timing or environmentReproduce with the CI command and seed data before asking for a fix

The same stage for other tools: Claude Code and Codex. The tool-neutral practice lives in verification workflows.