GPT-4o
⚙️ Technical
Intermediate
Unit Test Writer
Generate a complete unit test suite for your function or class, covering happy paths, edge cases, and error conditions.
The Prompt
# Unit Test Writer You are a test-driven development expert helping someone write comprehensive unit tests. ## The Code to Test - Language and test framework: [LANGUAGE/FRAMEWORK — e.g., Python/pytest, JavaScript/Jest, Go/testing] - Function or class to test: ``` [PASTE YOUR CODE HERE] ``` - What this code is supposed to do: [DESCRIPTION — e.g., validates user registration input, calculates shipping cost] - Known edge cases I'm worried about: [EDGE CASES — e.g., empty strings, negative numbers, null inputs, concurrent calls] - Mocking needs: [MOCKS — e.g., needs to mock the database, external API calls, or "none"] ## What I Need 1. A complete test suite with descriptive test names 2. Happy path tests (valid inputs, expected outputs) 3. Edge case tests (boundary values, empty, null, type errors) 4. Error condition tests (invalid input, exception handling) 5. Any setup/teardown or mock configuration needed
📝 Fill in the blanks
Replace these placeholders with your own content:
[LANGUAGE/FRAMEWORK — e.g., Python/pytest, JavaScript/Jest, Go/testing]
[PASTE YOUR CODE HERE]
[DESCRIPTION — e.g., validates user registration input, calculates shipping cost]
[EDGE CASES — e.g., empty strings, negative numbers, null inputs, concurrent calls]
[MOCKS — e.g., needs to mock the database, external API calls, or "none"]
How to use this prompt
1
Hit "Run it in your AI"
We open ChatGPT, Claude, Gemini, Perplexity, Grok or Copilot with this prompt in the box, ready for you to press Enter — and copied to your clipboard as a backup. Pick your AI once and we remember it.
2
Replace the placeholders
Swap out anything in [BRACKETS] with your specific details.
3
Send it
This prompt is tuned for GPT-4o, but it works well in any of them. Prefer to do it by hand? Copy to clipboard is always there too.
Get prompts like this every Monday
Free weekly digest — hand-picked prompts, new tools, AI news.