mockall

A powerful mock object library for Rust unit testing.

Library
Cargo
v0.15.0
1,844 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
57 /100 Fair
Development Activity 60
Maintenance 16
Community 52
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 84
Code Quality 85
Innovation 82
Learning Curve 62

Mockall is a feature-rich mock object library for Rust that lets you generate test doubles for traits and structs with a terse, ergonomic API. Mock objects share the interface of a real object but return responses your test code controls, letting you test upper layers of an application in isolation and inject error and edge cases that are hard to reproduce with the full stack.

Mocking is inherently harder in a statically typed language, and Mockall solves it by combining derive-style code generation (#[automock]) with an explicit mock! macro for cases the attribute cannot cover. It supports generic methods, associated types, static methods, sequences, and expectation matching — all in 100% safe, stable Rust.

What You Get

  • The #[automock] attribute to auto-generate a mock from a trait
  • The mock! macro for mocking structs and cases automock cannot reach
  • Expectation matching on arguments via composable predicates
  • Control over return values, call counts, and call sequencing
  • Support for generic methods, associated types, and static methods

Common Use Cases

  • Unit testing business logic without its real dependencies
  • Injecting error and edge cases that are hard to trigger live
  • Verifying that collaborators are called with expected arguments
  • Asserting the order and number of calls to a dependency

Under The Hood

Architecture — Mockall is a Cargo workspace of three crates: mockall is the runtime/public facade users import, mockall_derive is the procedural macro crate that does the heavy lifting, and mockall_double is a small helper for swapping real and mock types under cfg(test). The derive crate’s src/ is organized by what it mocks — mockable_item.rs, mockable_struct.rs, mock_trait.rs, mock_item_struct.rs, mock_function.rs, and automock.rs — parsing the annotated item and code-generating a corresponding MockXxx type with expectation plumbing.

Tech Stack — Written in 100% safe, stable Rust (MSRV 1.77). It builds on syn/quote/proc-macro2 for macro expansion in mockall_derive, and on the predicates crate to power argument matching in the public API. The workspace uses resolver 2 and pins dependencies for a checked-in MSRV lockfile.

Code Quality — The project is mature and well tested, with integration examples in mockall/src/examples.rs, a detailed CHANGELOG, CODEOWNERS, and CI across multiple toolchains including an explicit MSRV job. Being pure safe/stable Rust with no nightly requirements is a deliberate quality goal stated in the README.

API Design — Ergonomics are the selling point: #[automock] turns a trait into a mock with almost no ceremony, while the mock! macro provides an escape hatch for structs and complex generics. Expectations read fluently (expect_foo().with(eq(4)).times(1).returning(...)), and predicate composition keeps argument matching expressive. The main learning curve is knowing when automock suffices versus when the more verbose mock! macro is required.

Used by 7 apps in this directory

Rust
73%
Other

iii

Developer Tools · Devops

18,814

Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.

View details
87
Repo Health
85
Technical
65
Dependency
Built with
Rust 73%
TypeScript 16%
Updated 5 days ago
Rust
78%
AGPL 3.0

Lemmy

Community · Social Media

14,614

Federated, self-hosted Reddit alternative with full community ownership and no corporate control.

View details
89
Repo Health
74
Technical
62
Dependency
Built with
Rust 78%
PLpgSQL 14%
Updated 1 weeks ago
C++
66%
Other

Memgraph

AI Development · Databases

4,581

High-performance in-memory graph database for AI context and real-time analytics

View details
90
Repo Health
79
Technical
69
Dependency
Built with
C++ 66%
Python 18%
Updated 5 days ago
C++
66%
Other

Memgraph

AI Development · Databases

4,581

High-performance in-memory graph database for AI context and real-time analytics

View details
90
Repo Health
79
Technical
69
Dependency
Built with
C++ 66%
Python 18%
Updated 5 days ago
Python
100%
Other

OpenBB

Analytics · Databases · Invoicing Finance

73,553

The AI Workspace for Finance: Connect Data, Run AI Agents, Build Analytics

View details
77
Repo Health
80
Technical
67
Dependency
Built with
Python 100%
Updated 4 days ago
Rust
64%
Apache 2.0

Temps

Analytics · Devops · Monitoring

801

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
70
Dependency
Built with
Rust 64%
TypeScript 34%
Updated 4 days ago
Rust
79%
Apache 2.0

TensorZero

Ab Testing Experimentation · AI Development · Monitoring

11,717

TensorZero unifies the LLM gateway, observability, evaluation, optimization, and experimentation stack behind a single OpenAI-compatible API, built in Rust for sub-millisecond p99 latency.

View details
53
Repo Health
87
Technical
69
Dependency
Built with
Rust 79%
TypeScript 15%
Updated 3 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers