
Mocking Stubbing
This handles test isolation by replacing dependencies with mocks, stubs, and spies so you can unit test without hitting real databases, APIs, or file systems. It covers Jest for JavaScript/TypeScript, unittest.mock for Python, and Mockito for Java, plus patterns for things like simulating errors and verifying interactions. The guidance on mocking at boundaries (repositories, services) rather than mocking everything you own is solid advice that will keep your tests maintainable. Best used when you need fast, deterministic tests and want to avoid the brittleness that comes from over-mocking internal implementation details.
- skills.sh installs
- 432
- GitHub stars
- 379
- last updated
- Aug 21, 2026
Install
$ npx -y skills add aj-geddes/useful-ai-prompts --skill mocking-stubbing --agent claude-codeInstalls into .claude/skills of the current project.
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,
) {}
Sponsors
Details
- Repository
- github.com/aj-geddes/useful-ai-prompts
- Categories
- Testing & QA, AI & Agent Building
- First seen
- Jun 3, 2026
More from aj-geddes/useful-ai-prompts
All 258- Data Migration Scripts430
- Correlation Tracing429
- Synthetic Monitoring427
- Canary Deployment426
- Service Mesh Implementation426
- Azure Functions424
- Data Replication Setup424
- Graphql Implementation424
- Polyglot Integration424
- Distributed Tracing418
- Multi Cloud Strategy418
- Anomaly Detection
- Causal Inference
- Classification Modeling
- Clustering Analysis
- Cohort Analysis
- Computer Vision
- Correlation Analysis
- Data Cleaning Pipeline
- Data Visualization
- Dimensionality Reduction
- Exploratory Data Analysis
- Feature Engineering
- Funnel Analysis