codingintermediate

Test Generator

Generates comprehensive unit tests for a function or module with edge cases and mocks.

Prompt

Generate comprehensive unit tests for the following {{language}} code using {{testFramework}}.

Requirements:
- Cover happy path, edge cases, error conditions, and boundary values
- Use descriptive test names that explain the expected behavior
- Group tests logically using describe/context blocks
- Include setup and teardown where needed
- Mock external dependencies (network, filesystem, database)
- Aim for branch coverage, not just line coverage
- Add comments explaining WHY each edge case matters

Code to test:
```{{language}}
{{code}}
```

Public API or function signatures to focus on:
{{signatures}}

Variables

{{language}}{{code}}{{testFramework}}{{signatures}}

Example Output

describe("calculateDiscount", () => {
  it("returns 0 for orders below minimum threshold", () => {...

Use Cases

  • Bootstrap test suites for untested code
  • Increase coverage on critical paths
  • TDD red-green-refactor workflow

Compatible Models

claude-sonnet-4-20250514gpt-4ogemini-2.5-pro

Tags

testingunit-teststddcoverage

Details

Author
PromptIndex
Updated
2026-04-01
Difficulty
intermediate

Related Prompts

  • Code Review Assistant

    Performs a thorough code review covering correctness, performance, security, and maintainability.

  • Bug Finder

    Identifies bugs, edge cases, and potential runtime errors in a code snippet.

  • Refactoring Assistant

    Suggests and implements refactoring improvements while preserving behavior.