Unit Test Generator

Generate comprehensive unit tests for code

intermediate
codingtestingunit-testsquality

Prompt Template

Write unit tests for the following {language} code:

```{language}
{code}
```

Testing framework: {framework}

Cover:
1. Happy path (normal inputs)
2. Edge cases (empty, null, boundary values)
3. Error cases (invalid inputs, exceptions)
4. Any async behavior

Follow {framework} best practices and use descriptive test names.

Variables

{language}

Example: TypeScript

{code}

Example: function divide(a: number, b: number): number { ... }

{framework}

Example: Vitest

Example Output

```typescript
describe('divide', () => {
  it('should divide two positive numbers', () => {
    expect(divide(10, 2)).toBe(5);
  });
  it('should throw on division by zero', () => {
    expect(() => divide(10, 0)).toThrow();
  });
});
```

Tips

  • Provide the full function signature
  • Mention any mocking requirements

More Prompts