rust-mocking

Generate trait-based mocks for Rust unit tests with mockall.

1|Updated Dec 30, 2025
One-click install
npx skills add https://github.com/gar-ai/mallorn --skill rust-mocking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-mocking
Source: https://github.com/gar-ai/mallorn/tree/main/.claude/skills/rust-testing-mocking
Command: npx skills add https://github.com/gar-ai/mallorn --skill rust-mocking

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provide trait-based mocks for Rust code to enable isolated unit tests.

Core Features & Use Cases

  • Automock generation for traits with mockall
  • Async mocking support using async_trait and tokio
  • Predicate-based argument matching for precise control
  • Return-value control and call-count management
  • Partial mocks with mockall_double for integration tests

Quick Start

Run cargo test to execute unit tests that use mockall-generated mocks against trait-based interfaces.

Frequently Asked Questions about rust-mocking

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

FAQPage Schema
How do I mock Rust traits for isolated unit tests?

Mock Rust traits for isolated unit tests by generating automocks with mockall, allowing you to simulate external service dependencies and control return values without modifying the original trait-based interfaces.

Can I mock asynchronous Rust traits using async_trait and tokio?

Yes, you can mock asynchronous Rust traits by combining async_trait and tokio within mockall, enabling isolated unit tests for asynchronous code paths that rely on external services or complex dependencies.

What is the best way to control mock behavior with predicate-based matching in Rust?

Predicate-based matching in Rust mocking allows precise control over mock behavior by matching argument values to specific return outputs, and you can further validate interactions using call counting and sequences.

Does mockall support partial mocks for Rust integration tests?

Yes, mockall supports partial mocks for Rust integration tests through integration with mockall_double, allowing you to mock only specific trait methods while retaining real implementations for others.

When do I need trait-based mocks for Rust modules?

You need trait-based mocks for Rust modules when testing code that relies on external services or complex dependencies, enabling you to isolate synchronous and asynchronous logic for reliable unit testing.