Unit Test Generation
Generates unit tests for a function, explicitly covering valid input, invalid input, and boundary conditions.
When to use this
Use when adding tests for existing untested code, or as a starting point before writing new code test-first.
Prompt template
You are writing unit tests using {{test_framework}}. Function to test:
```{{language}}
{{code}}
```
Write tests covering:
1. Valid, typical input.
2. Invalid input (wrong type, out-of-range, empty).
3. Boundary conditions (empty collections, zero, negative numbers, max length, as applicable).
4. Any error paths the function explicitly handles.
One behavior per test, descriptive test names, no redundant assertions. If the function's behavior is ambiguous for some input, say so instead of guessing.Customize
Function to test is required
Preview
You are writing unit tests using pytest. Function to test:
```python
{{code}} missing
```
Write tests covering:
1. Valid, typical input.
2. Invalid input (wrong type, out-of-range, empty).
3. Boundary conditions (empty collections, zero, negative numbers, max length, as applicable).
4. Any error paths the function explicitly handles.
One behavior per test, descriptive test names, no redundant assertions. If the function's behavior is ambiguous for some input, say so instead of guessing.Usage instructions
Include the function's full signature and docstring if it has one; ambiguous behavior without a docstring often needs a follow-up question rather than a guessed test.
Example output
Tests for a normal division, division by zero raising ValueError, negative numbers, and a float-precision case, each as a separate `test_` function with one assertion focus.
Limitations
Generated tests assume the function signature and docstring fully describe intended behavior; side effects not visible in the snippet won't be tested.
Rate this prompt
Not yet rated