• Sign in

Get new prompt packs + offers

Occasional emails. No spam. Unsubscribe anytime.

© 2026 Prompt Chains

Browse packsCoursesFAQPrivacyTerms
  1. Prompts
  2. Tech Tools
  3. Write Unit Tests for a Function

🧪

Write Unit Tests for a Function

Generate a focused test suite covering happy path and edge cases.

Best with

Claude
Tech ToolsAIAutomation

0 views

1
# CONTEXT:
2
I have a function with little or no test coverage. I want a tight suite that proves it works on normal input AND catches the edge cases that break things in production. The common failure is tests that only check the happy path, or brittle tests coupled to internals.
3
4
# ROLE:
5
You are a test engineer who has shipped high-coverage suites for payment and auth systems where a missed edge case means real money or a breach. Before writing anything, think step by step: (1) What are the function's inputs, outputs, and side effects? (2) What are the boundaries and failure modes (empty, null, zero, negative, max, malformed, concurrent)? (3) Which cases give the most coverage per test?
6
7
# RESPONSE GUIDELINES:
8
Group tests: happy path, edge cases, error handling. One behavior per test, descriptive names, arrange-act-assert. Mock only true external dependencies. Note any input that can't be reasoned about without more info.
9
10
# TASK CRITERIA:
11
1. **Coverage of boundaries**: cover empty/null, min/max, zero/negative, malformed, and the documented error paths.
12
2. **Independent + deterministic**: no shared state, no reliance on test order, no real network/clock unless mocked.
13
3. **Readable**: each test name states the scenario and expected result.
14
**AVOID**: testing private internals, over-mocking, one giant test asserting everything, non-deterministic tests.
15
**FOCUS ON**: behavior at the edges and the contract the function promises.
16
17
# INFORMATION ABOUT ME:
18
- Function under test: Paste functionPPaassttee ffuunnccttiioonn
19
- Language/test framework: Insert · default: , "Python/pytest", "JS/Jest" OR "DEFINE FOR ME"IInnsseerrtt ·· ddeeffaauulltt:: ,, ""PPyytthhoonn//ppyytteesstt"",, ""JJSS//JJeesstt"" OORR ""DDEEFFIINNEE FFOORR MMEE""
20
- Known constraints or contract: Insert or "not specified"IInnsseerrtt oorr ""nnoott ssppeecciiffiieedd""
21
22
# RESPONSE FORMAT:
23
**Cases covered:**
24
| Category | Scenario | Expected |
25
|----------|----------|----------|
26
**Test code:**
27
```LanguageLLaanngguuaaggee
28
Complete, runnable test fileCCoommpplleettee,, rruunnnnaabbllee tteesstt ffiillee
29
```
30
**Coverage gaps / can't test without more info:** Bulleted list or "none"BBuulllleetteedd lliisstt oorr ""nnoonnee""

Related prompts

🐛
Debug & Fix Code (Root Cause)

Tech Tools · Text prompt

Find the true defect behind a bug and return corrected, tested code.

Claude

Tech ToolsAI

0

Open

🎫
Support Ticket Classifier

Automation · Text prompt

Auto-labeling inbound support tickets with category, sentiment, urgency, and a human-handoff flag for routing.

Claude

AutomationAI

3

Open

🧹
Refactor Code for Readability

Tech Tools · Text prompt

Clean up code for clarity and structure without changing behavior.

Claude

Tech ToolsAI

2

Open