Unit Test Generator

MR
@Mike Rodriguez
4 days ago
Fork

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
Edge Cases
  • Empty inputs
  • Null/undefined values
  • Boundary values (min, max)
  • Single item vs multiple items
Error Cases
  • 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:

  1. Complete test file
  2. Any helper files needed (mocks, fixtures)
  3. Explanation of testing strategy
  4. Coverage expectations

Variables 4

Test Framework {{test_framework}}
e.g., Jest, Vitest, Pytest, Go testing
Language {{language}}
e.g., TypeScript, Python, Go
Code to Test {{code}}
Paste the function or class you want to test...
Testing Context {{testing_context}}
e.g., This is a payment processing service that calls Stripe API