testing-strategy
Skill26 starsChanged 6 months agoMITView on GitHub
Use when the user writes tests, asks "should I write a test for this?", chooses between unit/integration/e2e, sets up a test runner, or hits flaky tests. Covers what to integration-test vs unit-test, testing the contract not the implementation, fakes vs mocks, and flaky-test triage.
- Deletes or force-pushes
54 other projects use a version of this.
Adopted by
Most recently taken up by
- jDxve/avengers-kittheir own version, first seen Nov 8, 2026
- nisarth/claude-skills-storetheir own version, first seen Nov 8, 2026
- ccoalm/ccl-skillstheir own version, first seen Nov 8, 2026
- komluk/scaffoldingtheir own version, first seen Nov 7, 2026
- bmsuisse/skillstheir own version, first seen Nov 6, 2026
- Cure-Consulting-Group/ProductEngineeringSkillstheir own version, first seen Nov 4, 2026
Used with
Projects with it also use api-contract-design, deploy-checklist and 9 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MohOneXSkillapi-contract-design
Designs and reviews API contracts (REST, RPC, GraphQL, library interfaces) for evolvability, backward compatibility, and failure semantics. Use when defining new endpoints/interfaces, versioning an API, reviewing a schema, or deciding how breaking changes propagate to clients.
Also in 3 projects that use this
AnthropicSkilldeploy-checklist
Pre-deployment verification checklist. Use when about to ship a release, deploying a change with database migrations or feature flags, verifying CI status and approvals before going to production, or documenting rollback triggers ahead of time.
Also in 4 projects that use this
xenitV1Skillreact-patterns
Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.
Also in 4 projects that use this
AnthropicSkilltech-debt
Identify, categorize, and prioritize technical debt. Trigger with "tech debt", "technical debt audit", "what should we refactor", "code health", or when the user asks about code quality, refactoring priorities, or maintenance backlog.
Also in 4 projects that use this
MicrosoftSkillapi-design
Guide for designing and documenting RESTful APIs. Use when asked to design an API, create endpoints, or document an API.
Also in 9 projects that use this
Microsoft AzureSkillrelease-readiness
Complete ODIN release documentation and validation checks before declaring user-visible work complete, preparing a release, or opening the Release-to-main pull request.
Also in 3 projects that use this
- +4 more from anthropics
Other versions54 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 54
- anthropics/knowledge-work-plugins★ 35ksame name
- chthollyphile/folia-major★ 12ksame name
- Community-Access/accessibility-agents★ 409same name
- AnastasiyaW/claude-code-config★ 214same name
- AnastasiyaW/codex-claude-code-config★ 214same name
- irahardianto/awesome-agv★ 157same name
- Blushyes/reef★ 84same name
- shinpr/agentic-code★ 51same name
- addxai/enterprise-harness-engineering★ 44same name
- drafthq/draft★ 40same name
44 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- api-route-hardeningSkill
- auth-and-sessionsSkill
- authorizationSkill
- caching-and-invalidationSkill
- database-query-safetySkill
- data-privacySkill
- error-handlingSkill
- file-uploadsSkill
- input-validationSkill
- jobs-and-queuesSkill
- llm-endpoint-safetySkill
- migrations-and-schemaSkill
- observabilitySkill
- production-readinessSkill
- reliability-patternsSkill
- rsc-boundariesSkill
- secrets-and-envSkill
- transactions-and-consistencySkill
- webhooksSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 44 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Test what callers depend on, not how it's done internally.
- Distinctive: line 42
Run unit on every save, integration on every push, E2E on every PR.
- Very specific: line 72
Don't test that useState updates state.
- Distinctive: line 87
If test B depends on test A having run first, the suite is fragile.
- Very specific: line 120
If you added a sleep(), you patched a symptom.
“Common” is measured: kept by at least 6 in 10 of the 44 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Testing Strategy
Tests are not a moral virtue. They are an investment with a return: catch regressions, document behavior, enable refactors. Write the tests that pay back; skip the ones that don't.
When to use
- Writing tests for new code
- Asking "should I write a test for this?"
- Choosing test type for a feature
- Setting up the test runner / CI
- Diagnosing a flaky test
- Reviewing a PR's test coverage
When to skip
- Throwaway scripts and prototypes you'll delete
- One-off internal tooling
The mental model: test the contract
Test what callers depend on, not how it's done internally. If a refactor preserves behavior but rewrites every line, the tests should still pass. If they don't, they were testing the wrong thing.
// BAD — tests the implementation
expect(spy).toHaveBeenCalledWith({ format: 'iso', tz: 'UTC' })
// GOOD — tests the behavior callers see
expect(formatDate(new Date('2026-05-07'))).toBe('2026-05-07')The pyramid (still right, just adapted)
| Layer | Speed | What it covers | Volume |
| Unit | <1ms | pure logic, edge cases of a single function | many |
| Integration | 10–500ms | function + its real DB / real Redis / real auth | medium |
| E2E | seconds | full flows: signup → checkout, in a real browser | few |
Run unit on every save, integration on every push, E2E on every PR. Do not invert this. A 12-minute test suite kills feedback.
The rules
1. Default to integration tests for backend code.
A unit test of a function that just calls Drizzle and Zod tells you nothing — it tests the function's invocation of mocks, not its behavior. Integration tests with a real Postgres (Testcontainers, ephemeral schema, or pglite for blazing speed) are where bugs actually live.
// vitest + Testcontainers
import { GenericContainer } from 'testcontainers'
beforeAll(async () => {
pg = await new GenericContainer('postgres:16').withExposedPorts(5432).start()
// run migrations against this DB
})2. Mocks lie. Use real things or fakes; mocks are the last resort.
| What it is | When | |
| Real | actual implementation in test | DB, Redis, your own code |
| Fake | a working alternative impl (in-memory queue, fake clock) | when "real" is too slow/external |
| Stub | returns canned data | trivial values |
| Mock | asserts on how it was called | last resort, brittle |
Mocks couple your tests to implementation details. Every refactor breaks a mock-heavy suite.
3. Test the boundaries you control. Trust libraries and frameworks.
Don't test that useState updates state. Don't test that Drizzle's eq() builds the right SQL. Test your function that uses these, against the input/output your callers see.
4. Each test: arrange, act, assert. Independent and ordered-doesn't-matter.
it('rejects expired sessions', async () => {
// arrange
const session = await createSession({ expiresAt: pastDate() })
// act
const result = await validateSession(session.id)
// assert
expect(result.ok).toBe(false)
})If test B depends on test A having run first, the suite is fragile. Each test sets up its own world (transaction rollback, fresh DB, factory functions).
5. Fast resets, not isolated test runners.
For Postgres integration tests:
- Best: each test in a transaction, rolled back at end. Sub-millisecond reset.
- Good: truncate tables between tests.
- Bad: drop & recreate DB per test.
6. E2E: cover the golden path + a couple of critical errors. Not coverage.
Playwright/Cypress for: signup, login, the core action your product exists to do, payment, data export. Not for: every form field, every empty state. Those go in component / integration tests.
A green E2E suite that takes 90 minutes to run gets disabled within a quarter. Keep it under 5.
7. Determinism > everything. A flaky test is a bug.
// BAD — depends on real time
expect(post.createdAt).toBeLessThan(new Date())
// GOOD — inject the clock
expect(post.createdAt).toEqual(fixedNow)Sources of flake:
- Real time (
Date.now(),setTimeout) — use a fake clock (vi.useFakeTimers()) - Real network — use real local services or MSW for HTTP mocking
- Order dependence — tests share state they shouldn't
- Race conditions in the code under test — fix the code, don't add
await sleep(100)
8. The "I added a sleep() to fix the flake" rule.
If you added a sleep(), you patched a symptom. Find the actual race. Promise.all, missing await, async event you didn't wait for — there's a real reason.
9. Snapshot tests: yes for stable output, no for everything.
Snapshots are great for:
- Generated API responses where the schema rarely changes
- Stable component renders with deterministic input
Snapshots are bad for:
- Anything with timestamps, IDs, randomness (use serializers to redact, or test specific fields)
- Big trees where every change "fix" is a thousand-line snapshot diff that no one reads
10. CI signal beats local signal.
Tests must pass on the CI box, not just on yours. Common reasons CI fails when local passes:
- Different timezone (
TZ=UTCin CI, but you're inAmerica/Los_Angeles) - Different filesystem (case-sensitive on Linux, case-insensitive on Mac)
- Tests racing because CI parallelism > local
- A test that creates a file in cwd
Fix: pin timezone, run case-sensitive locally, run with the same parallelism as CI.
11. Coverage % is the wrong number to watch.
Coverage tells you what ran under test, not whether the test caught anything. A 95% coverage suite that asserts nothing is worthless. Watch:
- Mutation testing (
stryker-mutator) for "do tests catch bugs?" - Bug recurrence rate — bugs you've fixed and shipped a regression test for shouldn't recur
12. Type tests for type-heavy code.
import { expectTypeOf } from 'vitest'
expectTypeOf<UserInput>().toMatchTypeOf<{ email: string; age: number }>()Generic-heavy library code earns type tests; everyday app code usually doesn't.
What "good" looks like
| Code shape | Default test |
| Pure function with branches | unit, table-driven over inputs |
| Route handler / Server Action | integration with real DB |
| React component with logic | component test (Testing Library), focus on behavior |
| End-to-end user journey | one E2E per flow, golden path + 1-2 errors |
| Generic types | type-level test |
War story
A startup's CI suite grew to 14 minutes and 800 tests, mostly mock-heavy unit tests of route handlers. They refactored from REST to tRPC, broke ~600 tests (all the mocks), and the team gave up on tests for a quarter. The replacement: 80 integration tests against a real Postgres (Testcontainers), 4 minutes total, caught more regressions than the previous 800 ever had.
Quick checklist
- Tests exercise behavior, not implementation
- Backend logic uses integration tests (real DB) by default
- Mocks only as last resort; prefer real or fake
- Each test self-sufficient (no order dependence)
- Fast reset (transaction rollback) between integration tests
- E2E covers golden path; doesn't try to cover everything
- No
sleep()band-aids; flakes are bugs to fix - Time / random / network injected, not real
- Coverage isn't the goal; bug recurrence is
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

