/ce:writing-testsfrom ce
Guides writing behavior-focused tests using the Testing Trophy model with real dependencies and minimal mocking. Helps choose between unit, integration, and E2E tests, fix flaky tests, and speed up slow test suites.
Ships in ce. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
If the current repo has its own testing rules or skills (check .claude/rules/ and the repo CLAUDE.md), those take precedence. Apply this skill where they're silent.
Test what a user or caller can observe, using real dependencies, so tests survive refactoring and fail only when behavior breaks.
The check for any test: a refactor that improves the code without changing what the app does must leave it passing, so the same test proves the behavior is unchanged before and after. A test that breaks on such a refactor hard-codes or stubs an assumption about the internals, which is the usual failure of unit tests.
Most tests should be integration tests written as behavior tests (the Testing Trophy: integration is the widest layer, with fewer unit and E2E tests around it). Enter through an interface a user or caller really uses, such as an HTTP route, a CLI command, a rendered component or a service's public function. Run it against the real database and real internal modules, then assert on the observable result. Name each test for the behavior ("rejects a duplicate email"), not the function it calls.
Integration is the default because it covers the wiring between units, which is where most bugs live, and it survives refactoring because it knows nothing about internals. Isolated unit tests of code with dependencies mostly end up testing the mocks.
Reach for another type only when it fits:
| Type | Use it for | Don't use it for |
|---|---|---|
| Unit | Edge cases a behavior test can't reach, and pure logic (parsers, calculations, validators, state machines) whose input combinations are too many to run through the interface | Cases a behavior test already covers, and anything that needs a mock of your own module to run. Write an integration test instead |
| E2E / acceptance | A handful of critical journeys (sign-up, checkout, login) through the deployed stack in a real browser, and behavior only the full stack shows: browser quirks, deployment wiring, third-party redirects | Edge cases and error branches. Cover those at the integration level, where tests are faster and less flaky |
When unsure, write the integration test.
Mock only what you don't own or can't control: external HTTP APIs, third-party services (payments, email), time and randomness. Use the real database, real internal modules and real business logic. When a mock is needed, make it match the real API's shape, including error responses.
| Context | Assert on | Not on |
|---|---|---|
| UI | Visible text, roles, labels | CSS classes, component state |
| API | Status and response body | Rows in the database behind it |
| Library | Return values and raised errors | Private methods |
| Pattern | Instead |
|---|---|
| Asserting a mock was called | Assert the outcome the call produced |
| Test-only methods in production code | Put helpers in test utilities |
sleep(500) before an assertion | Wait for the condition (findBy, waitFor, Playwright auto-wait, polling helpers) |
| Asserting internal state | Assert observable output |
A behavior test is not only the happy path. Drive the real entry point through the combinations and edge cases real use produces: inputs in the order and shapes callers send them, chained and mixed operations, state left over from an earlier step, failures of the things it depends on, and the near misses it must not get wrong. One realistic flow often exercises what several contrived single-function tests would, and it keeps doing so through a refactor. Give each realistic case its own row so a failure names it.
Find the cases by asking what real users, machines and data will throw at the code, not only the cases you had in mind while writing it. Bugs cluster in a few places:
There are two ways to get a test to the state an edge case starts from:
Prefer the first. It survives a refactor of anything between the entry point and the state, because it knows only what the user does. Use the second when the steps are impractical to replay (they take days of simulated time, or need a system you can't drive), and keep the data as realistic as what the steps would produce.
Reach for a unit-style test only when a behavior test can't reach the edge case either way, or when the combinations of a pure function are too many to run through the interface. Don't add one to repeat what a flow already covers.
Size the suite to the behaviors, not the inputs: one case per rule, branch or contract, plus one near miss per kind of false positive. Rows that run another spelling of the same input down the same path, or repeat every case across an independent dimension, add cost and make the behavior expensive to change. Before trimming a suite, prove each deleted test is redundant by breaking the code and its config one rule at a time and checking something still fails; references/test-value.md has the method.
A test that passes whether or not the behavior works protects nothing, and it reads exactly like one that does.
A slow test is a flaky test waiting for a busy machine: the suite runs in parallel on small CI runners, and a test that takes seconds alone times out there. Write each test so its cost is what it asserts and nothing more:
Check the cost when you add tests: run the file with per-test durations shown and look at the slowest. references/slow-tests.md has the patterns in detail and how to catch them in the suite.
| Need | Read |
|---|---|
| TypeScript and React (Testing Library, MSW, Vitest/Jest) | references/typescript-react.md |
| Python (pytest, fixtures, async) | references/python.md |
| Go | references/go.md |
| Async waiting in TypeScript | references/waiting-typescript.md |
| Async waiting in Python | references/waiting-python.md |
| Tests that pass alone and fail in the suite, or fail intermittently | references/flaky-tests.md |
| Slow tests, or tests that time out only under load or on CI | references/slow-tests.md |
| How many tests a behavior needs, trimming a suite that repeats itself, sharding a slow one | references/test-value.md |
references/flaky-tests.md (opens in a new tab)references/go.md (opens in a new tab)references/python.md (opens in a new tab)references/slow-tests.md (opens in a new tab)references/test-value.md (opens in a new tab)references/typescript-react.md (opens in a new tab)references/waiting-python.md (opens in a new tab)references/waiting-typescript.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub rileyhilliard/claude-essentials --plugin ce12 skills in this plugin
/architecting-systemsGuides clean, scalable system architecture during the build phase. Use when designing modules, defining boundaries, structuring projects, managing dependencies, or preventing tight coupling and brittleness as systems grow./deliverTakes a feature, plan or RFC to production-ready code merged to main, with emphasis on architecture and code quality. Adopts or writes a phased plan, has it critiqued against the codebase, scaffolds contracts, runs parallel subagent lanes, lands and tags each phase on a feature branch as it finishes, reviews every lane with a capped review cycle, and merges to main after approval. Use when asked to execute, implement or ship a plan or RFC, for "have DA review it, then implement", "implement, review and merge to main", or for work that needs full review depth. For timeboxed or prototype work, use sprint./Other plugins' skills for the same job