Official Coding

Write unit tests for a function

Generate thorough unit tests covering normal cases, edge cases and error handling.

1.9k views 590 copies

Prompt

Write unit tests for the function below using [testing framework]. Cover:
- Typical inputs and expected outputs
- Edge cases such as empty values, boundaries and very large inputs
- Invalid input and error handling

Use clear test names that describe the behaviour being tested, keep each test focused on one thing, and add a short comment where the expected result is not obvious.

Function:
[paste function here]

Replace the values in [square brackets] with your own details before using the prompt.

Similar prompts

More coding prompts you might like.

View all
Official ChatGPT Claude +1

Code review assistant

Get a structured review of your code covering bugs, security issues, performance and readability.

Official ChatGPT Claude +1

Explain code line by line

Understand unfamiliar code with a clear, beginner-friendly explanation of what each part does.