Unit tests for a function
Useful tests for one function: normal cases, edge cases and error cases, in your project's style.
- Type
- Prompt
- Level
- Intermediate
- Time
- about 6 min
Results depend on the tool, the model and what you enter.
Fill in
What you type stays in this browser window. We store and send nothing.
- pytest
- Jest
- Vitest
- JUnit 5
- xUnit
- Arrange-Act-Assert with blank lines
- one test file per module
- fixtures instead of setup methods
- sentence-style test names
- mocks only for external services
Your prompt
Write unit tests for the following function using [Test framework]. Cover: two normal cases, the main edge cases (empty, null, boundary values) and at least one error case. One test per behaviour, descriptive names, no real network or database access. Follow this style: [Project style]. Before the code, briefly list which cases you cover and why. Function: [Function]
Matching tools
Tools from our catalog that this prompt works well with.
- ChatGPT Prices and limits
- Claude Prices and limits
- Cursor Prices and limits
How to use it
- Fill in the fields or tap a suggestion. Leave out names, addresses and other personal data.
- Copy the finished prompt into a tool of your choice.
- Run the suite. If a test fails, first work out whether the test or the function is wrong.
Works in these tools
Prompts work in many chat and generator tools. This selection comes from our catalog; prices as shown on the tool page.
- ChatGPT Free planfrom 8 USD per month
- Claude Free plan
- Cursor Free planfrom 8 USD per month
- GitHub Copilot Free planfrom $10
- Windsurf Free plan
Why does this work?
The list of cases before the code makes coverage easy to review. Avoiding real network calls keeps the suite fast and reliable.
Tips
- Also ask for a test that permanently guards against a bug you found.