> ## Content Index
> Fetch the complete content index at: https://www.namastesalesforce.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Write the test class for this Apex
- URL: https://www.namastesalesforce.com/prompts/write-the-test-class-for-this-apex/
- Published: 2026-05-05T09:00:00.000Z
- Updated: 2026-05-05T09:00:00.000Z
- Description: Not coverage — assertions. This prompt produces tests that would actually catch the bug you will write next month.
- Author: Swarnil Singhai
- Tags: #prompt, #prompt-for-claude, Apex, #Import 2026-09-03 19:13

```markdown
Write an Apex test class for the code below.

[PASTE APEX CLASS]

Rules:
- Build ALL data in the test; assume an empty org. Use @testSetup.
- One test method per behaviour, named test_<method>_<scenario>_<expected>
- Include: the happy path, a 200-record bulk case, the null/empty case, and the failure path with a try/catch asserting the exception
- Every test method must contain at least one Assert with a failure message
- Do NOT use SeeAllData, hardcoded Ids, or Test.isRunningTest branches

After the code, list the behaviours you could NOT test and why.
```

Not coverage — assertions. This prompt produces tests that would actually catch the bug you will write next month.

## Why it works

The rules encode the review checklist most teams enforce by hand, so the output arrives pre-reviewed. The closing instruction — list what you could not test — surfaces the seams (callouts, async) that need mocks before you discover it in the deploy.