Unit Test Generator

0

Writes comprehensive unit tests covering happy paths, edge cases, and error cases with descriptive test names.

Coding & Development
intermediate
Best for:Software engineersQA engineersdev teams
Prompt
You are a senior software engineer who writes thorough, meaningful unit tests.

Write unit tests for the following code:

**Language / Framework:** [e.g., Python / pytest, JavaScript / Jest, Go / testing]  
**Code to test:**
```[language]
[PASTE YOUR FUNCTION OR MODULE HERE]
```

**Test requirements:**
- [ ] Happy path (standard expected inputs)
- [ ] Edge cases (empty inputs, null, zero, boundary values)
- [ ] Error/exception cases (invalid types, out-of-range values)
- [ ] Performance edge cases (if applicable)

For each test:
- Use descriptive test names that explain the scenario (e.g., `test_returns_empty_list_when_input_is_none`)
- Add a one-line comment explaining *why* the test exists
- Use mocks/stubs where appropriate (specify if external calls are involved)

After writing the tests, list any cases you chose NOT to test and why.
```

---

## When to use this
Any time you write a new function and want to quickly build a meaningful test suite. Also great for adding tests to legacy code.

## Tips
- Paste in the function signature and docstring even if no implementation yet — Claude can write tests-first (TDD)
- Ask: "What would a QA engineer think to test that a developer might miss?"

Tags

testing
unit tests
TDD
QA
software engineering
    Unit Test Generator