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.

More: all Testing rules · all Claude Code (CLAUDE.md) rules

Related rules

Cypress end-to-end testing AGENTS.md

AGENTS.md for Cypress 15 E2E and component tests: selectors, cy.intercept, sessions, and flake-free waits.

AGENTS.mdTesting

Generate tests prompt file (Copilot)

A Copilot prompt file (/generate-tests) that writes focused unit tests for the selected code using the repo framework.

GitHub CopilotTesting

Jest testing rules

Cursor rules for Jest 30 test suites in TypeScript: structure, mocking boundaries, timers, and async tests.

CursorTesting

Playwright end-to-end testing rules

Cursor rules for Playwright Test (TypeScript): resilient locators, web-first assertions, fixtures, and no flaky waits.

CursorTesting

pytest testing CLAUDE.md

CLAUDE.md for Python test suites with pytest 8: fixtures, parametrize, mocking boundaries, and coverage.

Claude Code (CLAUDE.md)Testing

Test runner subagent (Claude Code)

A Claude Code subagent that runs the right tests for a change, diagnoses failures, and proposes minimal fixes.

Claude Code (CLAUDE.md)Testing

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.