Ready-to-use AI prompts for write unit tests — written for Software Engineer and easy to paste into ChatGPT, Claude or Gemini.
When you need write unit tests done, these software engineer prompts give you a fill-in-the-blanks starting point covering testing, unit tests, tdd. Fill in fields like test framework, language, style example and paste the result into ChatGPT, Claude, or Gemini.
Generate a test suite from a function
You are a test engineer writing [test framework] tests for a [language] codebase. Match this style: [style example].
Function under test:
<code>
[function]
</code>
First, list the behaviors worth testing as short bullet points: happy path, boundary values, invalid input, error paths, and any state or side effects. Ask yourself which of these a bug would realistically hide in, and mark those as priority.
Then write the tests, one assertion concept per test, with names that read as sentences describing the behavior. Use fixtures or mocks only where a real dependency would make the test slow or flaky. Return only the test file, ready to run, followed by a one-line note on any behavior you could not test and why.
Find the missing test cases
Here is a [language] function and its existing tests.
<function>
[function]
</function>
<tests>
[existing tests]
</tests>
Act as a QA engineer whose job is to break this code. Ignore line coverage; think about input space. Identify inputs and sequences that are currently untested and could produce wrong output, an unhandled exception, or corrupted state — empty and huge inputs, unicode, negative and zero values, duplicate calls, out-of-order calls, timezone and locale differences, and concurrent access if relevant.
Output a table: Scenario, Why it could break, Expected behavior. Then write the three highest-value missing tests in full. If the existing tests already cover the risky cases, say so plainly instead of padding the list.
Write a failing test that reproduces a bug
I have a bug: [symptom]. It appears in this code:
<code>
[code]
</code>
Environment: [environment].
Write a single minimal [test framework] test that fails today because of this bug and will pass once it is fixed. The test must assert the correct behavior, not the buggy behavior. Keep setup to the smallest thing that reproduces it.
After the test, explain in three sentences what the test proves and what root cause you suspect. Do not fix the code yet — I want the failing test first so the fix is verifiable.
How to use this prompt
Fill in the blanks. Type your details into each highlighted field of this write unit tests prompt — fields like test framework, language, style example — and it rewrites itself live.
Copy the prompt. Press Copy prompt to put the finished write unit tests prompt on your clipboard.
Paste into your AI model. Paste it into ChatGPT, Claude, Gemini, or any chat LLM to get your write unit tests result.
Review and iterate. Read the response as a software engineer would, then adjust fields like test framework, language, style example and re-run to sharpen it.
Fill-in fields explained
test framework
e.g. pytest / Jest / JUnit
language
Your language.
style example
paste one existing test to match
function
paste function
existing tests
paste existing tests
symptom
what you expected and what happened
code
paste relevant code
environment
language, framework, versions
Frequently asked
Which AI models does the Write Unit Tests prompt work with?
The Write Unit Tests prompts for Software Engineer are plain-text and model-agnostic — paste them into ChatGPT (GPT-4o), Claude, Gemini, Llama, or any other chat model.
How do I customize the Write Unit Tests prompt for my own use?
Fill in the 8 labelled fields (test framework, language, style example, …) before copying, or edit the [bracketed] text after you paste.
Are the Write Unit Tests prompts for Software Engineer free to use?
Yes. Every Write Unit Tests prompt here is free to copy and reuse, including for commercial and client work, with no sign-up.