/selamy-skills:prefer-fakes-over-mocksfrom selamy-skills
Use when choosing or reviewing test doubles — deciding between a fake, stub, or mock for a collaborator. Default to fakes (working in-memory implementations); reserve interaction mocks for the narrow cases where the interaction itself is the contract.
Ships in selamy-skills. 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.
None: SKILL.md is the whole skill.
When a test needs a stand-in for a collaborator (a database, clock, queue, HTTP client), reach for a fake before a mock in almost every case. A fake tests what the code does (observable state and behavior); an interaction mock tests how the code does it (the exact calls made) — and "how" is the part you most want to be free to change. This complements [[test-design]] (which covers test structure, and deliberately defers fakes-vs-mocks here) and pairs with [[sim-zero-mode]] for deterministic test environments.
Principles are language-agnostic; per-language bindings are at the end.
Grounded in Martin Fowler, Mocks Aren't Stubs / Fake, Don't Mock, and Software Engineering at Google (Test Doubles).
Default to a fake. A fake is a working implementation that behaves like the real collaborator (in-memory store, fake clock, in-memory queue). Tests built on fakes assert the outcome — the resulting state — so they read like a spec and survive refactors that preserve behavior.
Mocks couple tests to implementation. A test that asserts
verify(repo).save(x) or mock.assert_called_with(...) passes or fails based
on the call sequence, not the result. It breaks when you refactor internals
that still produce the right outcome, and — worse — it can stay green while
the real integration is broken, because nothing exercised a real
implementation. Brittle and low-signal.
A fake must stay faithful, or it lies. The risk with fakes is drift: the in-memory version diverges from production behavior. Counter it: the fake is owned and maintained by the team that owns the real component, and it runs against the same contract tests as the real implementation (one shared test suite, two implementations). A fake without contract tests is a liability, not an asset.
Prefer state verification over interaction verification. Assert the
observable result after the act (assert repo.get(id) == updated), not the
calls made to get there. Verify interactions only when the interaction is
the externally-observable behavior.
When a mock or stub is genuinely justified (keep it narrow):
OrderPlaced event", "must not call the payment API twice". Then verify
that one interaction, deliberately, not the whole call graph.Don't mock types you don't own. Mocking a third-party SDK couples your tests to its surface, which can change or which you may misunderstand. Wrap it behind your own narrow interface and fake that interface instead.
when(...).thenReturn(...) + verify(...) /
mock.assert_called* / expect(fn).toHaveBeenCalledWith(...) is testing
interactions — ask what state it should assert instead.A good fake costs real effort up front — you write a working implementation and keep it contract-tested. That cost is amortized across every test that uses it and pays back in tests that don't break on refactors. For a genuine one-off boundary you can't fake yet, a stub is the right, cheaper call — just don't let one-offs become the house style.
InMemoryUserRepo
implementing the same protocol) over unittest.mock / MagicMock; reserve
mock/monkeypatch for error injection and un-fakeable boundaries; assert on
the fake's resulting state, not assert_called_with.FakeXxx implementing the interface
over Mockito verify(...); if you must use Mockito, prefer stubbed returns +
state assertions over verify interaction checks; run the fake against the
interface's contract tests.jest.fn()
/ vi.fn() spies; keep toHaveBeenCalledWith for the rare interaction-as-
contract case.gomock; idiomatic
Go already favors interface + fake; reserve generated mocks for interaction
contracts.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub selamy-labs/agent-skills --plugin selamy-skills111 skills in this plugin
/adaptive-estimationUse when tracking a slowly-varying latent quantity from noisy measurements with quantifiable uncertainty — a drifting metric, capacity, latency trend, or confidence. Prefer a Kalman-style adaptive estimator over fixed moving averages or static thresholds./adaptive-loop-budgetingUse when an autonomous loop needs explicit limits on attempts, time, cost, tool calls, verification depth, or risk, and a clear stop, continue, yield, or escalate decision./adopt-and-deleteUse when adopting a shared module, library, chart, or service, or doing any consolidation, migration, or refactor that supersedes existing code. The change that adds the replacement must REMOVE what it replaced, in the same atomic change.Other plugins' skills for the same job