mock-strategy-guide

Create mock implementations for testing Rust code with external dependencies.

2|1|Updated Oct 31, 2025
One-click install
npx skills add https://github.com/EmilLindfors/claude-marketplace --skill mock-strategy-guide
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mock-strategy-guide
Source: https://github.com/EmilLindfors/claude-marketplace/tree/main/plugins/rust-testing/skills/mock-strategy-guide
Command: npx skills add https://github.com/EmilLindfors/claude-marketplace --skill mock-strategy-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

You are an expert at testing strategies for Rust, especially creating mock implementations for hexagonal architecture. When you detect testing needs for code with dependencies, proactively suggest mocking strategies.

Core Patterns

  • Pattern 1: Simple Mock Repository
  • Pattern 2: Mock with Verification
  • Pattern 3: Mock with Controlled Failures
  • Pattern 4: Builder Pattern for Mocks

Quick Start

Use mocks to isolate tests and verify interactions.

Frequently Asked Questions about mock-strategy-guide

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

FAQPage Schema
How do I create mocks for Rust code that depends on external services?

Mocks isolate your Rust tests by replacing real dependencies like databases or HTTP services with controlled implementations. Use trait-based abstractions to define interfaces, then implement mock versions that return predefined data, enabling fast, reliable unit tests without infrastructure.

Can I verify that my mock was called with the right arguments in Rust tests?

Verification-enabled mocks track interactions—method calls and their arguments—during test execution. After running test code, assert that your mock received expected calls with specific parameters, catching integration bugs without touching real systems.

What's the best way to test error handling in Rust without hitting real failures?

Controlled-failure mocks let you inject specific errors into your test scenarios on demand. Configure mocks to return errors, timeouts, or invalid states, then verify your code handles each case correctly without depending on actual infrastructure failures.

How do I build flexible mocks for async Rust traits?

Builder-pattern mocks provide a fluent API to configure mock behavior before tests run. Chain methods to set return values, failure modes, and expectations, then pass the configured mock to your async code—simplifying complex test setups across hexagonal architectures.

Do mocks work with common Rust testing frameworks like tokio and common assertion libraries?

Yes. Mocks integrate seamlessly with standard Rust testing frameworks and async runtimes. They're compatible with trait-based repository and service patterns, letting you use familiar testing tools without additional dependencies or platform-specific workarounds.

When should I use mocks instead of integration tests for Rust?

Use mocks when you need fast feedback, isolated test cases, or cannot easily provision test infrastructure. Mocks excel at unit testing business logic; integration tests verify the real system end-to-end. Combine both—mocks for speed and coverage, integration tests for confidence.