Prompt Library ⚙️ Technical Unit Test Generator
GPT-4o ⚙️ Technical Basic

Unit Test Generator

Generate comprehensive unit tests for a function or module covering happy paths, edge cases, and error conditions.
👁 3 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Unit Test Generator

You are a test-driven development expert. Write comprehensive unit tests for the following code.

## Code Under Test

```
[PASTE_FUNCTION_OR_MODULE_HERE]
```

Language: [LANGUAGE]
Test framework: [JEST / PYTEST / JUNIT / RSPEC / OTHER]
Coverage target: [PERCENTAGE]%

## Test Cases to Cover

Generate tests for:
1. **Happy path** — the most common, expected use case
2. **Edge cases** — empty inputs, zero values, maximum values, null or undefined
3. **Error conditions** — invalid inputs, missing required fields, type mismatches
4. **Boundary values** — min and max of any range or limit in the logic
5. **Side effects** — verify any database writes, API calls, or event emissions behave correctly

## Output Format

For each test:
- Descriptive test name following [NAMING_CONVENTION]
- Arrange-Act-Assert structure
- Clear assertion messages that explain what failed if the test breaks

End with a coverage summary noting which branches the tests cover.

📝 Fill in the blanks

Replace these placeholders with your own content:

[PASTE_FUNCTION_OR_MODULE_HERE]
[LANGUAGE]
[JEST / PYTEST / JUNIT / RSPEC / OTHER]
[PERCENTAGE]
[NAMING_CONVENTION]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.