test-doubles-first
Select and implement the right test double with a default preference for fakes, stubs, and spies over mocks. Use when writing or refactoring tests, especially when users mention test doubles, mocking strategy, interaction assertions, or flaky tests caused by over-mocking.
- License 许可
- Unlicense
- 所属仓库
- saski/arnesto
- 最近更新
- 2026-11-12
- Stars
- ★ 6
- Forks
- 0
01 前言 Front Matter
- name
- test-doubles-first
- description
- Select and implement the right test double with a default preference for fakes, stubs, and spies over mocks. Use when writing or refactoring tests, especially when users mention test doubles, mocking strategy, interaction assertions, or flaky tests caused by over-mocking.
02 资源文件 3
- 参考文档references/examples.md1.6 KB
- 参考文档references/quick.md2.6 KB
- 参考文档references/usage.md3.2 KB
03 SKILL.md 正文
Test Doubles First
Quick Navigation
- Goal
- Default Rule
- Decision Tree
- Naming and Placement
- Style Constraints
- What Can Be Doubled
- Quick PR Smell Check
- Minimal Templates
Goal
Write tests that describe behavior and state, not implementation details. Avoid mock-by-default.
Default Rule
- Prefer state/output assertions first.
- Choose the lightest double that makes the test clear.
- Use mocks only when interaction contract is the behavior under test.
Decision Tree
- Can the test assert state (persisted data, returned value, emitted event)?
- Yes -> use a
Fake(in-memory or lightweight real implementation). - No -> continue.
- Yes -> use a
- Do you need to force a branch (success/failure/timeout) with controlled responses?
- Yes -> use a
Stub. - No -> continue.
- Yes -> use a
- Do you need to observe an outbound effect (email, message, metrics) without prescribing internal construction?
- Yes -> use a
Spy. - No -> continue.
- Yes -> use a
- Do you need to verify interaction contract (never called, called once, call order/protocol)?
- Yes -> use a
Mock, with minimal expectations.
- Yes -> use a
If one test needs many interaction expectations, treat it as a design smell and raise the abstraction of the port.
Naming and Placement
- Names
FakeXxxRepo,InMemoryXxxRepoStubXxxGateway,FailingXxxStub,FixedClockStubSpyXxxPublisher,SpyEmailServiceMockXxxClientonly for contract-driven tests
- Paths (cross-platform style)
- Python:
tests/doubles/ - TypeScript:
test/doubles/or__tests__/doubles/
- Python:
Always use forward slashes in paths.
Style Constraints
- Prefer state/output assertions over
called_withassertions. - For spies, assert only relevant facts (for example count, recipient, subject).
- Keep stubs configurable per scenario; do not build mini-systems.
- Keep fakes honest to domain invariants; add contract tests for real adapters when needed.
What Can Be Doubled
- Usually yes: ports to I/O (database, network, queues), time/randomness, email, logs, metrics.
- Usually no by default: value objects, entities, pure domain logic, internal mappers.
Quick PR Smell Check
- Would renaming an internal method break the test without behavior change? If yes, likely over-mocked.
- More than 2-3 interaction expectations in one test? Prefer fake/spy or redesign the port.
- Could the fake diverge from the real adapter? Add a contract test.
Minimal Templates
See references/examples.md for Jest-based JavaScript and TypeScript templates for fake, stub, spy, and contract-focused mock. See references/usage.md for trigger prompts and copy-paste templates. See references/quick.md for single-page fast reference.
04 同仓库更多 Skills
visualize
Use /visualize for creating compact charts, diagrams, or other visuals inline as part of the conversation itself. It chooses among Markdown tables, Mermaid, inline HTML, and other supported in-transcript forms. Use Canvas for durable artifacts outside the transcript that users may revisit, refine, or share.
update-cursor-settings
Modify Cursor/VSCode user settings in settings.json. Use when you want to change editor settings, preferences, configuration, themes, font size, tab size, format on save, auto save, keybindings, or any settings.json values.
update-cli-config
View and modify Cursor CLI configuration settings in ~/.cursor/cli-config.json. Use when the user wants to change CLI settings, configure permissions, switch approval mode, enable vim mode, toggle display options, configure sandbox, or manage any CLI preferences.
statusline
Configure a custom status line in the CLI. Use when the user mentions status line, statusline, statusLine, CLI status bar, prompt footer customization, or wants to add session context above the prompt.
split-to-prs
Split current work into small reviewable PRs. Use when the user asks to split a chat, set of changes, branch, or PR.
shell
Runs the rest of a /shell request as a literal shell command. Use only when the user explicitly invokes /shell and wants the following text executed directly in the terminal.