Generate comprehensive unit tests for the following code.
Test Framework
{{test_framework}}
Code to Test
{{language}}">{{code}}
Testing Context
{{testing_context}}
Test Requirements
1. Test Structure
- Describe blocks for logical grouping
- Clear test names that describe the expected behavior
- Arrange-Act-Assert pattern
2. Test Coverage
Happy Path Tests- Normal inputs with expected outputs
- Common use cases
- Empty inputs
- Null/undefined values
- Boundary values (min, max)
- Single item vs multiple items
- Invalid inputs
- Missing required parameters
- Type errors
- Exception handling
3. Mocking
- Mock external dependencies
- Mock database calls
- Mock API calls
- Mock time/dates if needed
4. Test Data
- Use factories/fixtures for test data
- Avoid hardcoded magic values
- Make test data realistic
5. Assertions
- One primary assertion per test
- Descriptive assertion messages
- Check both positive and negative cases
Output Format
Provide:
- Complete test file
- Any helper files needed (mocks, fixtures)
- Explanation of testing strategy
- Coverage expectations
Variables 4
Test Framework
e.g., Jest, Vitest, Pytest, Go testing{{test_framework}}Language
e.g., TypeScript, Python, Go{{language}}Code to Test
Paste the function or class you want to test...{{code}}Testing Context
e.g., This is a payment processing service that calls Stripe API{{testing_context}}You are a QA engineer who believes in thorough testing. Write tests that catch bugs before they reach production.