rust-testing

Standardizes Rust test doubles using mockall mocks injected through trait-object seams.

4|Updated Jun 21, 2026
One-click install
npx skills add https://github.com/NEETROF/cymbra --skill rust-testing-neetrof
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-testing
Source: https://github.com/NEETROF/cymbra/tree/main/.claude/skills/rust-testing
Command: npx skills add https://github.com/NEETROF/cymbra --skill rust-testing-neetrof

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires mockall, async-trait.

What problem does it solve? Rust projects often accumulate inconsistent test doubles—hand-written fakes, ad-hoc stubs, and mocks mixed together—making tests hard to maintain and review. This Skill enforces a single convention: default to mockall-generated mocks for trait dependencies, with clearly documented exceptions for hand-written fakes. ## Core Features & Use Cases - Mock generation guidance: Shows how to apply #[cfg_attr(test, automock)] to traits (kept above #[async_trait]) and mock! for foreign traits, keeping mocks out of release builds. - Expectation patterns: Demonstrates expect_<method>() with .with(...), .returning(...), and .times(...) so call counts and arguments are verified automatically on drop. - Documented exceptions: Defines when hand-written fakes are acceptable—behavioural in-memory adapters, production-shipped fakes, and pure functions—each requiring a justification comment. - Use Case: When writing a unit test for a service that depends on a repository trait, generate a MockCatalogSearchRepo, set expectations for the exact call, and inject it via the existing Arc<dyn Repo> seam instead of writing a new fake struct. ## Quick Start Ask the assistant to write a unit test for a Rust module with a trait dependency using mockall mocks instead of a hand-written fake.

Frequently Asked Questions about rust-testing

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

FAQPage Schema
How do I mock a Rust trait for unit tests with mockall?▼

Add #[cfg_attr(test, automock)] above the trait definition, keeping it above #[async_trait] for async traits. This generates a MockFoo type you configure with expect_method(), .with(), .returning(), and .times(), then inject via Arc::new(mock).

When should I use a hand-written fake instead of a mockall mock in Rust?▼

Use a fake only when the double must behave across calls, such as an in-memory repository that dedups by content hash or an object store that returns stored bytes. Fakes shipped by production code and pure functions needing no double are also valid exceptions.

How do I mock a foreign trait I cannot annotate with automock?▼

Use the mock! macro from mockall to define a mock for traits you cannot modify, such as those from external crates. The generated mock supports the same expect_* expectation API as #[automock]-generated mocks.

Does mockall work with async traits in Rust?▼

Yes, mockall supports async traits when combined with the async_trait crate. Place #[automock] above #[async_trait] on the trait definition so the macro processes the trait before async transformation.

Why does mockall verify mock expectations automatically?▼

Mockall verifies call counts declared with .times(n) when the mock is dropped at the end of the test. If an expected call never happened or happened too many times, the drop triggers a panic that fails the test without manual assertions.