Skip to content

Structured guide for isolating unit tests with mocks, stubs, spies, and test doubles across Jest, unittest.mock, and Mockito.

CCM score
37 of 100
skills.sh installs
434
GitHub stars
396
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers creating and managing test doubles to replace databases, APIs, file systems, and other slow or non-deterministic dependencies
  • Includes reference guides for Jest, Python unittest.mock, Mockito for Java, and advanced mocking patterns, plus a TypeScript quick start
  • Provides a do and don't checklist, such as mocking at the boundary, resetting mocks between tests, and avoiding mocks in integration tests
  • Designed for unit test suites where dependency injection makes external services easy to replace with controlled doubles

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill mocking-stubbing -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Mocking and Stubbing

Table of Contents

Overview

Mocking and stubbing are essential techniques for isolating units of code during testing by replacing dependencies with controlled test doubles. This enables fast, reliable, and focused unit tests that don't depend on external systems like databases, APIs, or file systems.

When to Use

  • Isolating unit tests from external dependencies
  • Testing code that depends on slow operations (DB, network)
  • Simulating error conditions and edge cases
  • Verifying interactions between objects
  • Testing code with non-deterministic behavior (time, randomness)
  • Avoiding expensive operations in tests
  • Testing error handling without triggering real failures

Quick Start

Minimal working example:

// services/UserService.ts
import { UserRepository } from "./UserRepository";
import { EmailService } from "./EmailService";

export class UserService {
  constructor(
    private userRepository: UserRepository,
    private emailService: EmailService,
  ) {}

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Testing & QA, Backend & APIs
First seen
Jun 3, 2026

Questions

What does the mocking-stubbing skill do?

The mocking-stubbing skill creates and manages mocks, stubs, spies, and test doubles to isolate unit tests from external dependencies. It covers Jest mocks, Python unittest.mock, and Mockito for Java, and it teaches replacing slow or non-deterministic dependencies such as databases, network calls, and time with controlled doubles.

Who should use the mocking-stubbing skill?

Developers who write unit tests and need to isolate code from databases, APIs, file systems, or other slow dependencies will find the mocking-stubbing skill useful. It also helps when simulating error conditions or verifying interactions between objects in tests.

How do I install the mocking-stubbing skill?

Run npx -y skills add aj-geddes/useful-ai-prompts --skill mocking-stubbing -y inside your project. Once installed, the mocking-stubbing skill lets your agent write mocks, stubs, and spies for your unit tests.

Where does the mocking-stubbing skill sit in Testing & QA?

The mocking-stubbing skill is listed in the Testing & QA category on Claude Marketplaces, alongside tdd, test-driven-development, and webapp-testing. It stands apart by focusing specifically on test doubles and dependency isolation rather than on the wider test workflow.

More from aj-geddes/useful-ai-prompts

All 258

Similar to Mocking Stubbing

More Testing & QA