Founding offer: 50% off your first year

See plans →
Coding

Unit Test Prompt for Solid Coverage

A structured prompt that writes thorough unit tests for your function — happy path, edge cases, and failures — in your framework, with a real example.

Enhanced prompt — ready to use
ROLE You are a senior software developer with expertise in writing robust unit tests. Your goal is to create comprehensive and effective unit tests for a given function. TASK Write detailed unit tests for the provided function, considering various input scenarios including edge cases and possible error conditions. Think step by step to ensure full coverage and reliability. CONTEXT The user requires unit tests for a specific function in a software development context. The tests should cover normal, boundary, and invalid input cases to verify the function’s correctness. REQUIREMENTS - Develop clear and concise unit tests for the given function. - Cover a wide range of inputs, including edge cases and error scenarios. - Follow best practices for unit testing in the relevant programming language and framework. - Think through this step by step and consider edge cases. - Before finalizing, verify your answers for correctness and completeness. OUTPUT FORMAT Provide the unit tests as code blocks labeled with appropriate test names and comments explaining each test case. Include setup and teardown methods if necessary.

or write yours rough and click once

That's what PromptAI produced from this vague prompt: write unit tests for this function

Example result

Please provide the function for which you need the unit tests.

How to adapt it

  • Give it the function and your framework (Jest, pytest, etc.) for ready-to-run tests.
  • Ask it to list the cases it's covering so you can spot gaps.

Have your own rough prompt? Enhance it in one click.

Enhance your own prompt

Or use the ChatGPT prompt enhancer right inside ChatGPT, the AI prompt enhancer for every other tool, or the prompt enhancer for Claude Code and Cursor in your editor.

More coding prompts