testing · justxor — Claude Code rule: what it does, how to install
testing sets automated test standards for Claude Code: Arrange-Act-Assert structure, banned sleep calls, and strict boundaries for mocks.
MIT ★ 353 updated 2026-10-01
.claude/rules/testing.mdWhat testing does
The rule targets test files matching **/*.test.*, **/*.spec.*, tests/**, and __tests__/**. It requires every test to follow the Arrange → Act → Assert pattern with exactly one scenario per test. Test names must describe concrete behavior, such as returns 404 when task does not exist.
Mocks are restricted strictly to external systems: network calls, time, and the filesystem. Mocking internal application code is forbidden. Tests must not call sleep; instead, they must rely on fake timers or explicit waits.
Weakening assertions just to make a test pass is prohibited. If code behavior changes deliberately, the agent must state that change explicitly.
What it helps with
- enforce Arrange → Act → Assert structure with one scenario per test
- restrict mocks strictly to network, time, and filesystem boundaries
- replace
sleepdelays with fake timers and explicit waiting - prevent weakening test assertions when checks fail
Example prompts for the agent
- Write unit tests for the auth service in tests/auth.test.ts
- Refactor api.spec.ts to replace sleep with fake timers
- Add a test verifying returns 404 when task does not exist
How to install testing
Manually: put the files in place
.claude/rules/testing.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/testing.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/testing.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/testing.mdManually: put the files in place
.clinerules/testing.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about testing
How to install testing in Claude Code?
Create the file .claude/rules/testing.md in your repository and paste the rule text into it.
Which file paths does the testing rule affect?
It applies to **/*.test.*, **/*.spec.*, and all paths inside tests/** or __tests__/**.
Does this rule allow mocking internal helpers?
No, internal application code must not be mocked. Mocks are permitted only for external systems like network, time, and the disk.
Source text
testing.md · MIT
--- paths: - "**/*.test.*" - "**/*.spec.*" - "tests/**" - "__tests__/**" --- # Правила для тестов - Структура: Arrange → Act → Assert, один сценарий — один тест. - Имена тестов описывают поведение: `returns 404 when task does not exist`. - Моки — только для внешних систем (сеть, время, файловая система). Свой код не мокаем. - Никаких `sleep`: используй фейковые таймеры и явное ожидание. - Не ослабляй проверки, чтобы тест прошёл. Если поведение изменилось намеренно — скажи об этом явно.
© justxor · MIT · justxor/claude-code-pro-course
Similar IDE rules
All IDE rules for Testing and QA →testing by other authors comes first.