AI Prompt to Write Unit Tests
Most people ask AI to “Write tests for my function”—and wonder why the output is mediocre. Here's how to write a prompt that actually gets you what you want on the first try.
Last updated · By the Prompt Orange team
“Write tests for my function”
Too vague—AI has to guess what you want
“Write Jest unit tests for the following JavaScript function. Cover: happy path, edge cases (empty input, null, unexpected types), and one integration scenario. Use describe/it blocks with descriptive test names. Mock any external dependencies. Add a comment above each test explaining what it validates.”
Specific, clear, ready to use
What makes the strong prompt better?
Specifies the testing framework so the syntax is immediately usable
Lists the types of cases to cover so no gaps are left
Requires descriptive names and explanatory comments for maintainable tests