Intermediate
Best Claude Prompt for Tests & Docs
Why Claude?
Claude generates comprehensive test suites by reasoning about edge cases, not just happy paths. For documentation, it writes precise technical prose that matches the code's actual behavior — it won't invent behavior or over-promise.
Prompt Template
<role>
You are a senior engineer who writes tests that actually catch bugs, not tests that just pass. Your documentation is precise, terse, and honest — if behavior is undefined in edge cases, you say so rather than inventing an answer.
</role>
<code_context>
Language: {{language}}
Testing framework: {{test_framework}}
Function/module to test: {{target_function}}
{{code}}
</code_context>
<instructions>
Part 1 — Test Suite:
Generate a complete test suite for the code above. Include:
- Happy path tests (2-3 cases)
- Edge cases (empty input, null/None, boundary values, maximum values)
- Error cases (invalid input types, expected exceptions)
- Any concurrency or state mutation risks if applicable
For each test, add a one-line comment explaining WHAT it is testing and WHY it could fail.
Part 2 — Documentation:
Write a docstring/JSDoc comment for the function that includes:
- One-sentence summary of what it does
- Parameters with types and constraints
- Return value with type
- Exceptions it raises
- One usage example
- Any known limitations or edge cases the caller should know about
</instructions> Example Output
```python
def test_chunk_list_even_division():
# Basic case: list divides evenly into chunks
Show full example
assert chunk_list([1,2,3,4], 2) == [[1,2],[3,4]]
def test_chunk_list_uneven_division():
# Last chunk should be smaller, not dropped
assert chunk_list([1,2,3,4,5], 2) == [[1,2],[3,4],[5]]
def test_chunk_list_empty_input():
# Empty list should return empty list, not raise
assert chunk_list([], 5) == []
def test_chunk_list_size_larger_than_list():
# Size > len(lst) should return one chunk with all elements
assert chunk_list([1,2,3], 10) == [[1,2,3]]
def test_chunk_list_size_one():
# Each element becomes its own chunk
assert chunk_list([1,2,3], 1) == [[1],[2],[3]]
def test_chunk_list_size_zero_raises():
# size=0 causes ZeroDivisionError in range() — should this be ValueError?
with pytest.raises((ZeroDivisionError, ValueError)):
chunk_list([1,2,3], 0)
```
Docstring:
```python
def chunk_list(lst: list, size: int) -> list[list]:
"""Split a list into consecutive chunks of the given size.
The final chunk may be smaller than size if len(lst) is not evenly divisible.
Args:
lst: Input list. May be empty.
size: Maximum number of elements per chunk. Must be >= 1.
Returns:
List of sublists. Returns [] if lst is empty.
Raises:
ZeroDivisionError: If size == 0 (current behavior — consider validating).
Example:
>>> chunk_list([1, 2, 3, 4, 5], 2)
[[1, 2], [3, 4], [5]]
Limitation: Does not validate that size > 0. Caller must ensure size >= 1.
"""
```
Make it yours
Your Generated Prompt
Prompt copied! What's next?
Got your AI output? Make it better.
Paste what Claude generated into Coda One — free, no signup.
Tips for Better Results
Ask Claude to also generate property-based test suggestions (e.g. for use with Hypothesis) for algorithmic functions. For documentation, specify the audience: internal dev doc vs. public API doc changes the tone significantly.
Example (filled in)
<role>
You are a senior engineer who writes tests that actually catch bugs, not tests that just pass. Your documentation is precise, terse, and honest — if behavior is undefined in edge cases, you say so rather than inventing an answer.
</role>
<code_context>
Language: Python
Testing framework: pytest
Target: chunk_list() in src/utils/lists.py
def chunk_list(lst: list, size: int) -> list[list]:
return [lst[i:i+size] for i in range(0, len(lst), size)]
</code_context>