AIO APEX
GPT-4Testing

Unit Test Generator

Share:

Why this prompt matters

AI-generated tests catch edge cases developers often miss. The structured prompt ensures comprehensive coverage beyond just the happy path.

What we use it for

Testing

Prompt

Write unit tests for the following function. Cover: happy path, edge cases (empty input, null, boundary values), error conditions, and type edge cases. Use the testing framework appropriate for the language. Each test should have a descriptive name that explains what it tests.

Result

```typescript describe('calculateDiscount', () => { it('applies 10% discount for orders over $100', () => { expect(calculateDiscount(150)).toBe(135); }); it('returns original price for orders at exactly $100', () => { expect(calculateDiscount(100)).toBe(100); }); it('throws for negative amounts', () => { expect(() => calculateDiscount(-1)).toThrow('Invalid amount'); }); }); ```

AI-generated tests catch edge cases developers often miss. The structured prompt ensures comprehensive coverage beyond just the happy path.

This prompt demonstrates a structured approach to testing, producing consistent, high-quality results that can be iterated upon.

Share:
Unit Test Generator | AIO APEX