Skip to main content
AIPromptIndex
GitHub Copilot Coding intermediate

Comprehensive Unit Test Generator

Added Apr 1, 2026

You are a senior QA engineer who advocates for thorough test coverage. Write comprehensive unit tests for the following [LANGUAGE] code: [CODE_TO_TEST]. Use [TESTING_FRAMEWORK] as the testing framework. Generate tests that cover: happy path scenarios, edge cases (empty inputs, null values, boundary conditions), error handling and exception throwing, input validation, and any side effects. For each test, include a descriptive test name that explains the expected behavior using the pattern 'should [expected behavior] when [condition]'. Add comments explaining why each edge case matters. Group tests logically using describe/context blocks. Aim for at least 90% code coverage.
0
Share
Try in GitHub Copilot

About This Prompt

Writing thorough unit tests is tedious but critical for code reliability. This prompt generates test suites that go far beyond basic happy-path testing to cover the edge cases and error conditions that cause production bugs. The descriptive naming convention makes test failures immediately understandable, and the logical grouping structure keeps large test files navigable. The emphasis on explaining why each edge case matters helps developers understand their own code's vulnerability surface. Invaluable for establishing testing patterns on legacy codebases or maintaining coverage standards on fast-moving teams.

Variables to Customize

[LANGUAGE]

Programming language of the code

Example: TypeScript

[CODE_TO_TEST]

The function or class to write tests for

Example: function calculateShippingCost(weight: number, destination: string, isExpedited: boolean): number

[TESTING_FRAMEWORK]

Which testing framework to use

Example: Jest with ts-jest

Tips for Best Results

  • Paste your actual function implementation for tests that match real behavior
  • Ask for integration tests as a follow-up for functions with external dependencies
  • Request mock setup for functions that call APIs or databases

Example Output

```typescript
describe('calculateShippingCost', () => {
  describe('standard shipping', () => {
    it('should return base rate of $5.99 when weight is under 1lb', () => {
      expect(calculateShippingCost(0.5, 'US', false)).toBe(5.99);
    });

    it('should add $1.50 per additional pound when weight exceeds 1lb', () => {
      expect(calculateShippingCost(3, 'US', false)).toBe(8.99);
    });
  });

  describe('edge cases', () => {
    // Zero weight could indicate a digital product or data error
    it('should throw InvalidWeightError when weight is zero', () => {
      expect(() => calculateShippingCost(0, 'US', false)).toThrow(InvalidWeightError);
    });
```
testing unit-tests TDD code-quality QA

Get the Best AI Prompts Weekly

Curated prompts, tips, and guides delivered to your inbox every week. Free.