Back to guide/Developer Tools

Test Generation for Cursor

The @-mention gives Cursor the actual file content. Requiring it to check existing test patterns first ensures new tests match the project's style rather than generic defaults.

cursor-ai-tipsfile_to_testtest_frameworktest_file_path
Edit View
Prompt
Generate tests for @{{file_to_test}}.

Test framework: {{test_framework}}
Test file location: {{test_file_path}}

Requirements:
- Look at existing tests in the project first (check {{test_directory}}) and match their patterns
- Test the public exports only
- Include these categories:
  * Happy path (normal inputs, expected outputs)
  * Edge cases (empty, null, boundary values)
  * Error cases (invalid input, network failures, timeouts)
- Mock {{dependencies_to_mock}} using the project's existing mock patterns
- Each test name should describe the scenario: "should [expected behavior] when [condition]"

Do NOT test implementation details like private functions or internal state.

Variables to customize

{{file_to_test}}{{test_framework}}{{test_file_path}}{{test_directory}}{{dependencies_to_mock}}

Why this prompt works

The @-mention gives Cursor the actual file content. Requiring it to check existing test patterns first ensures new tests match the project's style rather than generic defaults.

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.