Skip to content
Back to skills

Test Mocking Strategies

ASecurity

Picks the right test double for each dependency (real object, fake, stub or spy) so tests stay fast without mocking away the behavior they should verify.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 15, 2026
ai-agents

Works with

  • cli

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill test-mocking-strategies --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Test Mocking Strategies?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Test Mocking Strategies
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-test-mocking-strategies/badge)](https://www.skillsdirectory.com/skills/workspace-templates-test-mocking-strategies)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: test-mocking-strategies
description: Picks the right test double for each dependency (real object, fake, stub or spy) so tests stay fast without mocking away the behavior they should verify.
---

# Test mocking strategies

Use the least fake double that keeps the test fast and deterministic.

## Decide per dependency

1. **Real object** when it is pure, in memory and cheap: value types, parsers, formatters. Never mock these.
2. **Fake** (a working simplified implementation) for stateful collaborators you own: an in-memory repository, a fake clock, a local queue. Share one fake across the suite and test it against the same contract as the real one.
3. **Stub** for a canned answer from something slow or external: an HTTP client returning a fixed response, including error and timeout cases.
4. **Spy or mock** only when the call itself is the behavior: an email sent, a payment charged, an event published. Assert the arguments that matter, not the call order.

## Rules

- Mock at the boundary you own, such as your own payment client wrapper, not the third-party SDK's internals.
- Assert outcomes (return value, stored state, emitted event) before interactions.
- Never mock the class under test, and never stub a private method.
- If a test needs more than three doubles, the unit has too many dependencies: say so and suggest the split.
- Keep stubs honest: build responses from recorded real payloads or the published schema.

## Report

For a review: each test with a smell, the double it uses, the better choice and why. For new tests: which doubles you chose and the reason for each.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.