Back to Prompt Library
Coding
TestingTDDQuality AssuranceCoding

Unit Test Generator

Generates a thorough, well-organized test suite covering happy paths, edge cases, and errors.

Prompt Template

Write a comprehensive unit test suite for the following [LANGUAGE] function/class using [TEST FRAMEWORK — Jest/Pytest/JUnit/etc.]. Code: [PASTE CODE HERE] Include tests for: (1) the happy path (expected inputs producing expected outputs), (2) edge cases (empty strings, null/undefined, zero, negative numbers, maximum values), (3) error cases (invalid inputs that should throw or return errors), (4) any async behavior if applicable. Use descriptive test names in the format 'should [expected behavior] when [condition]'. Add a brief comment explaining what each test group is validating. Aim for at least 90% branch coverage.

How to use this prompt

  1. Copy the prompt template using the button above.
  2. Paste it into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.).
  3. Replace all bracketed placeholders like [TOPIC] with your specific details.
  4. Send the prompt and refine the output as needed.
Advertisement