74 / 87 · 02 AI-Augmented Test Design · Copilot and Cursor as Test-Writing Copilots← prev⊞ allnext →☰ Read as one page
11.4Cursor Workflow: Iterative Test Development
Cursor combines an IDE with AI chat and a codebase index. It is the middle ground between Copilot's inline completion and Claude Code's full agent capabilities.
The Workflow
1. Open the source file and the test file side by side
2. Select the function under test
3. Cmd+K (or Ctrl+K): "Generate tests for this function covering:
- all return paths
- the ValueError on line 34
- the edge case where items list is empty"
4. Review generated tests in diff view
5. Accept, modify, or reject each test individually
6. Run tests inline, iterate on failures
Cursor Strengths
- Codebase-aware. Cursor indexes your entire project using embeddings, so it knows about files you have not opened.
- Interactive diff view. You see exactly what Cursor wants to add/change and can accept or reject line-by-line.
- Chat + code. You can ask Cursor questions about the code ("What does this function do when the list is empty?") before generating tests.
- Terminal integration. Cursor can run tests via its integrated terminal and iterate on failures.
Cursor Weaknesses
- Smaller effective context than Claude Code. The index is good for retrieval, but very large specs can still exceed what fits in a single request.
- IDE lock-in. You must use Cursor as your editor (it is a VS Code fork).
- No autonomous iteration. Unlike Claude Code, Cursor does not run-fix-run in a loop. You must manually trigger each iteration.
Cursor Best Practices for Test Generation
1. Use @-mentions to reference files:
Generate tests for the PaymentService class.
@app/services/payment.py (source)
@tests/test_user_service.py (style reference)
@docs/openapi.yaml (specification)
2. Use Composer for multi-file generation: Cursor's Composer mode can generate tests across multiple files in a single session, similar to Claude Code but with visual diff review.
3. Iterate with chat:
User: "These tests look good but they don't test the case where
the Stripe API returns a card_declined error."
Cursor: [generates additional test for card_declined]
User: "Also add a test for the race condition where two orders
use the same idempotency key simultaneously."
Cursor: [generates concurrency test]