Home › Testing › Testing .claude/rules file
Testing .claude/rules file
A path-scoped Claude Code rules file that loads only for test files: structure, determinism, and never weakening tests.
Claude Code (CLAUDE.md)Testing
How to use
Save this as .claude/rules/tests.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
Note: Review and test before use. Provided as is, without warranty. See Terms.
.claude/rules/tests.mdDownload ---
paths:
- "**/*.test.*"
- "**/*.spec.*"
- "**/test_*.py"
- "**/*_test.go"
- "tests/**"
- "e2e/**"
---
# Working on tests
- Match the existing framework and helpers in this directory; read a neighboring test file before writing a new one.
- One behavior per test, named as a sentence. Arrange / act / assert.
- Use factories/fixtures for data; set only fields that matter to the assertion.
- Deterministic only: fake time, seed randomness, stub network at the boundary, no sleeps (wait on conditions instead).
- Assert observable behavior (outputs, responses, rendered text, persisted state), not private internals.
- Each new test must fail without the change it covers. When fixing a bug, show the failing run first.
- Run the single file you touched, then the related suite.
## Never
- Delete, skip, or `xfail` a test to get green.
- Change an expected value to match current output without explaining why the old expectation was wrong.
- Leave focused tests (`.only`, `fit`) or debug prints.
If a test seems wrong, stop and explain instead of editing it.