Home / Prompts / Coding / Best ChatGPT Prompt for Writing Unit Tests
💻 Coding Prompt

Best ChatGPT Prompt for Writing Unit Tests

Automated Test Case Generator
🔥 9.4K uses
🤖 ChatGPT / Claude
✅ Free to use
The Prompt
You are a senior QA engineer and testing specialist. Write comprehensive unit tests for the following code: Programming language: [LANGUAGE] Testing framework: [Jest / Mocha / PyTest / JUnit / other] Code to test: [PASTE YOUR FUNCTION OR CLASS HERE] Generate tests that cover: 1. Happy path — normal expected inputs and outputs 2. Edge cases — empty inputs, null values, boundary values 3. Error cases — invalid inputs, expected exceptions 4. Performance — if applicable For each test: - Write a clear test name that describes what is being tested - Follow the Arrange-Act-Assert pattern - Add a comment explaining why this test case matters Aim for 90%+ code coverage. Show the complete test file ready to run.

💡 How to use this prompt

  • Tell the AI which lines you're most worried about
  • Add "mock all external API calls" for isolated unit tests
  • Run the tests immediately — AI-generated tests sometimes have typos
Best Tools for This Prompt
🤖 Best AI Coding Tools for This Prompt
Tested & reviewed — run this prompt with the best AI tools
View All Tools →
Cursor AI
★ 4.6 Freemium / From $20/mo

About This Coding AI Prompt

This free Coding prompt is designed for ChatGPT / Claude and works with any modern AI assistant including ChatGPT, Claude, Gemini, and more. Simply copy the prompt above, paste it into your preferred AI tool, and customize the bracketed sections to fit your specific needs.

Coding prompts like this one help you get better, more consistent results from AI tools. Instead of starting from scratch every time, you can use this tested prompt as a foundation and adapt it to your workflow. Browse more Coding prompts →