Write tests prompt
A copy-and-paste prompt for ChatGPT, Claude or Gemini that gets a professional write tests on the first try, plus the cheapest model that does it well.
What most people type
write unit tests for this python function ```python def parse_price(s): s = s.replace('$','').replace(',','').strip() return round(float(s), 2) ```
It works, but the AI has to guess your test framework: pytest or unittest, so the first answer usually needs another round. The version below asks for exactly what a professional would deliver.
The better prompt
Write unit tests for this Python function using [test framework: pytest or unittest].
```python
def parse_price(s):
s = s.replace('$','').replace(',','').strip()
return round(float(s), 2)
```
Cover:
- Typical inputs: plain numbers, a "$" sign, thousands separators, surrounding whitespace, and combinations of these.
- Rounding behavior, including values with more than two decimals and half-way cases. Note that round() on floats can surprise, so state the expected result for each case.
- Edge cases: zero, negative values, very large numbers, and an input with no digits before or after the decimal point (such as ".5" or "5.").
- Invalid input: empty string, whitespace only, non-numeric text, and non-string input such as None. Assert the exception type that the current code actually raises.
Use parametrized tests where it keeps them compact, give each test a clear name, and add a one-line comment for any non-obvious case. If any test exposes questionable behavior in the function (for example, "1,00" or "$-5"), list it briefly after the tests. Don't change the function unless I ask.
Return the full test file in one code block.Replace the [brackets] with your details before you send it: test framework: pytest or unittest.
Why this version works
- Named test framework placeholder. Framework wasn't given; avoids guessing.
- Listed case categories to cover. Gets thorough tests for typical, edge and invalid input.
- Flagged float rounding and exception behavior. These are the likely failure points in this function.
- Specified output as one test file. Makes the result paste-ready.
What a professional write tests prompt covers
- Test framework such as pytest
- Edge cases such as empty string, negatives, bad input
- Return the test file only or format stated
Best AI model for this prompt
This is a everyday task: ordinary test writing, but needs care with float rounding and exception edge cases. You don't need the most expensive model. The cheapest model at each company that handles it well:
| Company | Model | Per use | Per 1,000 uses |
|---|---|---|---|
| Anthropic | Claude Sonnet 5.5 | $0.0075 | $7.51 |
| OpenAI | GPT-6.1 Terra | $0.0038 | $3.76 |
| Gemini 3.8 Flashcheapest | $0.0028 | $2.82 |
Pay-per-use list prices for this prompt and its expected answer (about 700 tokens). On a monthly chat plan, the same choice shows up as more messages before you hit your limit. See today's AI prices.