{
  "$schema": "https://promptfoo.tech/schemas/workflow-template.json",
  "name": "Cursor: Test Generation Workflow for Legacy Code",
  "slug": "cursor-test-generation-workflow",
  "platform": "Cursor",
  "category": "coding",
  "difficulty": "Advanced",
  "tags": [
    "cursor",
    "testing",
    "claude",
    "coding"
  ],
  "summary": "Use Cursor + Claude Sonnet to generate meaningful test suites for legacy code with zero coverage — using property-based tests where they matter.",
  "overview": "Every codebase has some corner nobody's written tests for and everyone's afraid to touch. This workflow uses Cursor's agent mode with Claude Sonnet 4 to read a module, infer its invariants, and write a test suite that exercises real behavior — not the trivial happy path. Property-based tests are added where they'd actually catch bugs.",
  "variables": {
    "ANTHROPIC_API_KEY": "sk-ant-..."
  },
  "steps": [
    {
      "order": 1,
      "name": "Choose the target module",
      "description": "Start with pure functions or single-responsibility modules. Avoid god-classes on first pass."
    },
    {
      "order": 2,
      "name": "Get a test plan first",
      "description": "Never let the model write tests without listing what it's going to test. This is where you catch redundancy and gaps."
    },
    {
      "order": 3,
      "name": "Test the plan yourself",
      "description": "Ask 'What would a malicious input to this function look like?' — include those cases in the plan explicitly."
    },
    {
      "order": 4,
      "name": "Generate the suite",
      "description": "Composer in agent mode with the plan pinned. Use Vitest or Jest — Claude does both fluently."
    },
    {
      "order": 5,
      "name": "Add property-based tests",
      "description": "For pure functions with clear invariants (sorting, encoding, math): fast-check or hypothesis."
    },
    {
      "order": 6,
      "name": "Run + iterate",
      "description": "For real failures, ask: bug or test wrong? Never let the agent fix code without you naming which."
    }
  ],
  "howItWorks": [
    "Open the file. Cmd-K → 'Draft a test plan (bullet list) before writing any tests.'",
    "Review the plan. Prune redundant cases, add missing edge cases.",
    "Cmd-K → 'Now write the tests according to the plan.'",
    "For pure functions: 'Add fast-check property-based tests for {invariant}.'",
    "Run tests. For failures, ask Composer to either fix the code or update the test with justification."
  ],
  "benefits": [
    "Coverage that matters, not coverage for coverage's sake.",
    "Property-based tests catch bugs handwritten tests never would.",
    "The test plan becomes documentation of what the module does."
  ],
  "useCases": [
    "Adding tests to a legacy module before refactoring it.",
    "Onboarding a new engineer — they read tests, not code.",
    "Post-incident: writing regression tests to lock in a fix."
  ],
  "example": "Function: parseHumanDate('yesterday'). Property test: 'For any date d, parse(format(d)) === d'. Handwritten test: parse('yesterday') at midnight boundary.",
  "faqs": [
    {
      "q": "Which model?",
      "a": "Sonnet 4 is the sweet spot. Opus for tricky legacy JS with implicit globals; overkill otherwise."
    },
    {
      "q": "Fake tests problem?",
      "a": "Real risk. Always run the tests and inspect at least 3 assertions manually per file."
    },
    {
      "q": "TDD-style?",
      "a": "Yes — flip the flow: write the plan, ask the model for a failing test, then write the implementation. Best for greenfield."
    }
  ],
  "source": "https://promptfoo.tech/workflows/cursor-test-generation-workflow",
  "updated": "2026-06-12",
  "license": "CC-BY-4.0"
}