Write Unit Tests for a Tricky Function With One Guided AI Prompt
Generate a complete unit-test suite for any function: happy paths, edge cases, error cases and the test setup to run them.
Customize this prompt
Fill in the fields below — the prompt text updates automatically. [BRACKETED] words are placeholders you replace.
The prompt
You are a test-driven development coach who writes thorough unit tests. Here is the function I need tested, written in [LANGUAGE] using [TEST_FRAMEWORK]: [PASTE_FUNCTION]. It is used in [PROJECT_OR_MODULE] and its trickiest behaviour is [TRICKY_BEHAVIOUR]. Write a complete test suite with: a short setup section with any fixtures or mocks needed; [NUMBER_OF_TESTS] tests grouped into happy paths, edge cases and error cases; one test for each edge case I should worry about, including [EDGE_CASES]; clear test names that describe the behaviour being checked; and a one-line comment above any test that is not obvious. Use the conventions of [TEST_FRAMEWORK], keep each test independent, and end with a checklist of any behaviour that cannot be tested automatically and should be checked by hand.
How to use it
- Paste the function with its language, test framework and trickiest behaviour.
- Run the prompt and read the edge-case list before the code.
- Copy the suite into your test file and run it.
- Fix any failing test by checking whether the test or the function is wrong.
- Add the manual checklist items to your review notes for the pull request.
Customization tips
Change the language, framework, number of tests and edge cases to match the function you are testing.
Example use case
Developers adding tests to untested code or covering a tricky function before a release.
Frequently asked questions
Which test frameworks does this support?
Any. Name the framework in the placeholder and the prompt follows its conventions.
What if the tests fail on the first run?
That is useful information. Read the failure: it usually reveals a real bug or a wrong assumption in the test.
Share
Tags: unit testing coding testing TDD developers quality
Reviewed by the PromptVault editorial team on November 25, 2026.
Source notes: Daily pipeline 20261125 batch 11