CheckOps home

Tools directory

M

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Generated mocks: #[automock] and mock!.
  2. Rich expectations: Predicates, counts, sequences and closures.
  3. Broad support: Generics, async traits, statics and foreign functions.
  4. Automatic verification: Checked when the mock is dropped.

Pros

  1. Free to use: Open source under the MIT or Apache-2.0 licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 3 November 2026.

Cons

  1. Macro complexity: Error messages from generated code can be hard to read.
  2. Trait-based design required: Code must depend on traits to be mockable.
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.

  1. Rust teams testing code that depends on traits for I/O and services.
  2. 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.