Testing Slash Commands
Slash commands for every job in the test lifecycle: generation, maintenance, coverage, and infrastructure. Framework-aware, style-matching, colocation-respecting — and refreshed within 48 hours of every release.
Why test-writing is the highest-ROI use of slash commands
Ask any Claude Code user which slash commands they wrote first, and testing shows up in the top three — usually alongside /commit and /review. The reason is simple math: writing tests is repetitive prompt engineering. You want the same framework detected, the same style enforced, the same edge cases considered, the same file colocation applied — every single time. That's exactly the pattern a slash command is designed for.
The 15 testing commands on this page are the field-tested set that our editorial team uses (and that community contributors submit variations of). Each is production-ready, framework-aware, and refreshed within 48 hours of every meaningful Claude Code or test-runner release.
What a great testing command looks like
The best test-writing commands don't just say "write tests". They:
- Detect the framework. Vitest, Jest, Pytest, RSpec, Mocha, Playwright — the command reads
package.json,pyproject.toml, or config files to pick the right style. - Mirror existing patterns. If your team uses
describe/itnested style, the new tests do too. If you prefer flattest.each, they follow that. - Colocate correctly.
Component.test.tsxnext toComponent.tsx? A__tests__/folder? Sibling_test.go? The command respects your convention. - Restrict tools appropriately.
Read,Grep,Glob, andWrite(tests/**|**/*.test.*). No arbitrary shell commands. No writing production code from a test command. - Force the right model. Unit tests? Sonnet is fine. E2E with complex flows? Opus earns its keep. Set
model:in the frontmatter so cost matches value.
Anatomy of /test-unit
Here's the shape of a well-written unit-test command:
Testing commands vs testing hooks vs testing subagents
All three shape Claude Code's testing behavior, and mature teams use them together:
- Slash command (
/test-unit) — on-demand test writing. Fires when you type it. Best for "add tests for this file I just wrote". - Hook (
auto-test-related) — automatic test runs after every write. Fires whether you asked or not. Best for enforcement: you can't leave broken tests behind. - Subagent (
test-coverage-analyst) — specialized delegated work in an isolated context. Best for "find the highest-value coverage gaps and write tests for them" — a long, exploratory task that would pollute your main conversation.
The recipe most teams converge on: /test-unit for daily test writing, a auto-test-related hook that runs affected tests on save, and a test-coverage-analyst subagent invoked weekly for gap hunting.
All 15 testing commands, grouped by job
Every command is production-tested against real projects and refreshed on a rolling 90-day cycle. Click any name for the full Markdown, frontmatter, and usage notes.
Which testing command should I use?
A quick decision framework for the situations teams hit most often.
model: opus in the frontmatter — the extra reasoning pays off for complex E2E flows with waits, fixtures, and page objects.Related sub-categories in Slash Commands
Testing pairs naturally with code review, refactoring, and debugging — the four commands most teams install together.
🐛 Hit an error while using these?
Our sister site AI Error Hub covers Claude Code errors, MCP connection failures, and stack traces — cross-referenced with everything on this site.
Frequently asked questions
The questions developers ask most about testing.
/test-unit is the go-to for most projects. It reads your package.json or pyproject.toml, detects your test framework (Vitest, Jest, Pytest, Mocha, RSpec), reads an existing test file to match your style, and colocates the new test next to the source.
Cost is low (Sonnet by default) and it's the highest-frequency testing command teams install first.
It reads your dependency manifest:
- JS —
package.jsondevDependencies forvitest,jest,mocha, orava. - Python —
pyproject.tomlorrequirements-dev.txtforpytest,unittest, ornose. - Ruby —
Gemfileforrspecvsminitest.
This is why the command works across stacks without manual config.
Slash command for on-demand, per-file work — /test-unit at the moment you finish the source file.
Subagent for longer, exploratory tasks — for example, delegating "find the top 10 coverage gaps and write tests for all of them" to a test-coverage-analyst subagent lets it work in an isolated context without polluting your main conversation.
Most teams use both.
Narrow ones. A test-writing command needs:
Read,Grep,Glob— to understand the file being tested and existing patterns.Write(**/*.test.*),Write(**/*.spec.*),Write(tests/**)— scoped to test paths only.
It should not have Bash access (tests aren't a place to shell out) and should not be able to write to non-test files. Narrow allowed-tools is the safety net.
Bake determinism rules into the command body. Explicitly instruct:
- No arbitrary sleeps — use
waitForwith conditions. - Reset state between tests — use before/after hooks with cleanup.
- Fix timezone and Date.now in test setup.
- Use test fixtures for auth rather than logging in during each test.
Force model: opus in the frontmatter — E2E test design benefits from the deeper reasoning.
Yes, on the common cases. It's most effective when given the failing test and recent CI history (which it reads via git log and, if configured, an MCP server for your CI provider).
Common patterns it recognizes:
- Awaited promises resolving in different orders
- Tests depending on execution order
- Non-deterministic date/random values
- Network timeouts
For deep environmental flakiness (Docker networking, GPU driver issues), you'll still need to dig manually.
Yes, and it's one of the highest-ROI hooks a team can install. The auto-test-related hook fires PostToolUse on Write/Edit events, detects which tests import the changed file, and runs just those.
If a test fails, the output goes back to Claude so it can fix on the same turn. Combined with /test-unit for authoring new tests, this pair keeps your test suite healthy without you thinking about it.
The command should detect your project's mocking approach and match it:
- Vitest →
vi.mock - Jest →
jest.mock - Network → MSW (browser + node),
nock, orvcrpy - Spies →
sinon
For network mocking specifically, /mock-external-apis generates MSW handlers, nock scopes, or vcrpy cassettes based on the API calls in the code.
Four commands cover most of what a team needs:
/test-unit— daily unit test authoring./test-e2e— critical user flows./coverage-check— periodic gap analysis./fix-flaky-test— the inevitable CI complaints.
Add /mock-external-apis if your project has significant third-party API dependencies. All five are on this page.
Yes. Pass the framework as an argument. For example:
/test-unit UserService.ts --framework=jest
…forces Jest even if the project uses Vitest elsewhere. Useful when you're incrementally migrating or supporting multiple test runners in a monorepo. The command's argument-hint field documents this.
Get the weekly Claude Code digest
Every Tuesday: new testing, Anthropic release recap, and the best community submission. 13,000+ developers read it.