tdd-mocking-isolation

Installation
SKILL.md

Mocking & Dependency Isolation

Testing in isolation ensures that your unit tests are fast, deterministic, and fail only when the logic inside the unit is broken.

Test Double Types

  • Dummy: Passed around but never actually used (e.g., to fill a parameter list).
  • Stub: Provides canned answers to calls made during the test.
  • Spy: A stub that also records some information based on how it was called.
  • Mock: Objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
  • Fake: Have working implementations, but usually take some shortcut (e.g., an in-memory database).

Best Practices

  1. Don't Mock Everything: If a class is a pure data object or a simple utility, use the real thing.
  2. Mock Only What You Own: Avoid mocking third-party libraries; wrap them in an interface instead.
  3. Verify Behavior, Not Implementation: Focus on what the mock should receive, not the internal state of the mock.

Example (Python)

from unittest.mock import MagicMock
Installs
1
GitHub Stars
1
First Seen
Jun 29, 2026
tdd-mocking-isolation — jcorpac/ai-skills-library