CLSkills
Software Development

How to Use Claude for Writing Tests

The exact prompt, setup, and codes to get great results.

The Problem

Writing tests is tedious and most developers skip edge cases. Coverage reports show green but the tests don't actually catch real bugs because they only test the happy path.

The Prompt (Copy & Paste)

Write comprehensive tests for this code.

Language: [LANGUAGE]
Test framework: [JEST / PYTEST / RSPEC / etc.]
Code to test:

```[language]
[PASTE CODE]
```

Requirements:
1. Happy path tests (basic expected behavior)
2. Edge cases (empty inputs, null/undefined, boundary values, very large inputs)
3. Error cases (what should throw/fail and how)
4. Integration-relevant scenarios (if this interacts with other components)

For each test:
- Descriptive test name that explains the scenario
- Arrange-Act-Assert structure
- Only mock what's necessary (no over-mocking)
- Add a comment explaining WHY each edge case matters

Replace the [BRACKETED] placeholders with your specific details.

What You Get

A test suite that actually catches regressions. Edge cases you wouldn't think of, descriptive names that serve as documentation, and mocks only where necessary.

Prompt Codes That Help

Add these prefix codes to the start of your prompt for even better results:

Click any code to see its before/after examples and learn how it works.

Want all 120+ prompt codes?

The Claude Prompt Cheat Sheet has every tested code with before/after examples, combo stacks, and 10 workflow playbooks for different roles.

More Software Development Tasks

πŸ“¬

Get new prompts + workflows weekly

Join developers and professionals getting tested Claude prompt codes, workflows, and real-world techniques. One email when there’s something worth sharing.