test-doubles-choice

Selects the correct test double type for unit tests based on what each test verifies.

1|Updated Jul 3, 2026
One-click install
npx skills add https://github.com/Nandansai08/skillz --skill test-doubles-choice-nandansai08
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: test-doubles-choice
Source: https://github.com/Nandansai08/skillz/tree/main/skills/testing-qa/test-doubles-choice
Command: npx skills add https://github.com/Nandansai08/skillz --skill test-doubles-choice-nandansai08

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Test suites often drown in mocks that break on every internal rename and verify nothing real. This Skill guides the choice between stub, fake, spy, and strict mock so each double matches what the test actually verifies, and flags suites suffering from overmocking. ## Core Features & Use Cases - Double-type selection: Maps verification targets to double types — state verification to stubs and fakes, interaction contracts to spies, and must-not-happen requirements to strict mocks. - Boundary guidance: Recommends doubling owned interfaces and wrapping vendor SDKs in thin adapters instead of mocking 40-method third-party clients. - Fake verification: Prescribes contract tests that run the same suite against both the fake and the real implementation to prevent drift. - Use Case: A suite with 30 tests each patching six Stripe SDK methods fails 22 tests on an internal rename. The fix introduces a 3-method PaymentGateway adapter with a FakeGateway, nightly contract tests against real Stripe test mode, and one strict mock for double-charge protection. ## Quick Start Ask the AI to review your test file and recommend whether each mocked dependency should be a stub, fake, spy, or strict mock based on what the test verifies.

Frequently Asked Questions about test-doubles-choice

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between mock, stub, fake, and spy in unit tests?▼

Choose based on what the test verifies: stubs return canned data for state verification, fakes provide working lightweight implementations, spies record calls for interaction assertions, and strict mocks enforce must-not-happen requirements. Stubs are the default choice.

What is the difference between a mock and a stub?▼

A stub returns canned data so the test can verify state, while a strict mock fails on unexpected calls and verifies interactions. Stubs survive refactors because they assert on outcomes; mocks weld tests to implementation details and break on internal renames.

When should I use a fake instead of mocking the database?▼

Use a fake, such as an in-memory repository or SQLite standing in for Postgres, when many tests need realistic behavior like querying or uniqueness checks. One fake replaces dozens of per-test stub setups, but it needs contract tests against the real implementation.

Why do my tests break when I rename internal methods?▼

Tests break on renames when they mock private functions or assert on internal call sequences instead of state. Fix this by extracting pure logic, doubling owned boundary interfaces, and asserting on outcomes rather than collaborator calls.

Should I mock third-party SDK clients directly?▼

No. Wrap the vendor SDK in a thin adapter your team owns and double the adapter instead. Mocking a 40-method vendor client means vendor API churn breaks hundreds of tests, while an adapter confines breakage to one place.

When should I not use a test double at all?▼

Skip the double when extracting pure logic from the I/O call lets you test the logic directly, or when testing through the real dependency is the right move. The best double is no double; integration-test-strategy covers testing through real dependencies.