Back to guide/Developer Tools

Test Scaffolding Prompt

Referencing the exact file with #file gives Copilot Chat the full function signature and dependencies. Specifying the test framework, naming convention, and what to mock prevents generic tests that need heavy editing.

copilot-promptsfunctionNamefilePathtestFramework
Edit View
Prompt
Write unit tests for the {{functionName}} function in #file:{{filePath}}.

Use {{testFramework}} with the following structure:
- Group tests by behavior (describe blocks)
- Cover: happy path, edge cases (empty input, null, boundary values), and error cases
- Use descriptive test names: "should {{expectedBehavior}} when {{condition}}"
- Mock {{dependenciesToMock}} using {{mockLibrary}}
- Assert both return values and side effects

Variables to customize

{{functionName}}{{filePath}}{{testFramework}}{{dependenciesToMock}}{{mockLibrary}}{{expectedBehavior}}{{condition}}

Why this prompt works

Referencing the exact file with #file gives Copilot Chat the full function signature and dependencies. Specifying the test framework, naming convention, and what to mock prevents generic tests that need heavy editing.

Save this prompt to your library

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