CheckOps
Mockall
Mockall is a powerful mock object library for Rust, generating mocks for traits and structs with the #[automock] attribute or mock! macro, with expectations, predicates and call counts.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Mockall is a mock object library for Rust. Rust’s strict type system makes mocking harder than in dynamic languages, and Mockall uses procedural macros to generate mock implementations automatically: add #[automock] to a trait (or use the mock! macro for structs, external traits and generic cases) and a MockTrait type is created for tests.
Each mocked method gets an expect_method() builder where you set argument predicates (with(predicate::eq(4))), call counts (times(1), never()), ordering through sequences, and return values or closures (returning(|x| x + 1)). Mockall supports generic methods, async traits, static methods, foreign functions and non-'static references. Expectations are verified when the mock is dropped, so unmet expectations fail the test. It is dual-licensed MIT or Apache-2.0 and the repository had commits in November 2026; versions are published on crates.io.
The source code is at asomers/mockall on GitHub under the MIT or Apache-2.0 licence, with about 1,900 stars; the most recent commit was on 3 November 2026.
Features
- Generated mocks:
#[automock]andmock!. - Rich expectations: Predicates, counts, sequences and closures.
- Broad support: Generics, async traits, statics and foreign functions.
- Automatic verification: Checked when the mock is dropped.
Pros
- Free to use: Open source under the MIT or Apache-2.0 licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 3 November 2026.
Cons
- Macro complexity: Error messages from generated code can be hard to read.
- Trait-based design required: Code must depend on traits to be mockable.
Usage and Links (Example)
use mockall::{automock, predicate::*};
#[automock]
trait Payments {
fn charge(&self, amount: u32) -> Result<String, String>;
}
fn checkout(p: &dyn Payments, total: u32) -> bool { p.charge(total).is_ok() }
#[test]
fn charges_total() {
let mut mock = MockPayments::new();
mock.expect_charge()
.with(eq(100))
.times(1)
.returning(|_| Ok("tx-1".into()));
assert!(checkout(&mock, 100));
}
Resources:
Pricing
Mockall is free and open source under the MIT or Apache-2.0 licence.
Recommended for?
- Rust teams testing code that depends on traits for I/O and services.
- Async Rust services needing mocked dependencies.
Conclusion
Mockall is the standard mocking library for Rust, generating capable mocks that respect the type system.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Mockall side by side.
Rrstestrstest is an Apache-2.0 fixture-based and parameterised testing framework for Rust, offering pytest-style fixtures, #[case] tables, value matrices and async support on top of cargo test.Compare with Mockall
Pproptestproptest is a Hypothesis-inspired property-based testing framework for Rust, with composable strategies, automatic shrinking and persisted regression files.Compare with Mockall
Iinstainsta is an Apache-2.0 snapshot testing library for Rust by Armin Ronacher, with assert_snapshot! macros, serde-based formats, redactions, inline snapshots and the cargo insta review tool.Compare with Mockall
GGoMock (uber-go/mock)GoMock is an Apache-2.0 mocking framework for Go, maintained by Uber after the original golang/mock was archived, with the mockgen code generator and a gomock controller for expectations.Compare with Mockall
MMockitoMockito is the MIT-licensed, most popular mocking framework for Java, used to create mocks, stubs and spies with a clean API; Mockito 5 uses the inline mock maker by default and requires Java 11.Compare with Mockall
MMockKMockK is an Apache-2.0 mocking library built for Kotlin, supporting final classes, objects, coroutines, extension functions and top-level functions with a concise DSL.Compare with Mockall