$ mockall

v0.15.0

A powerful mock object library for Rust.

Downloads: 142.8M
Recent: 31.3M
Versions: 34
Updated: June 28, 2026

Latest Update Summary

Crate

Name: mockall New version: 0.14.0 Release date: 2025-11-22T17:52:07.546670Z

Crate readme

Short description A powerful mock object library for Rust.

Long description Mockall is a mock object library for unit testing in Rust, allowing controlled responses from mock objects that share interfaces with real objects. It is written in 100% safe and stable Rust, compatible with Rust 1.77.0 and higher. It simplifies testing by enabling the creation of mocks without involving the real implementations, thereby facilitating the testing of edge and error cases easily.

Features • Cargo feature flags • 100% safe and stable Rust • Compatible with Rust 1.77.0 and higher

Code Examples Add to Cargo.toml

 [dev-dependencies]
mockall = "0.14.0"

Basic usage

 #[cfg(test)]
use mockall::{automock, mock, predicate::*};
#[cfg_attr(test, automock)]
trait MyTrait {
    fn foo(&self, x: u32) -> u32;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn mytest() {
        let mut mock = MockMyTrait::new();
        mock.expect_foo()
            .with(eq(4))
            .times(1)
            .returning(|x| x + 1);
        assert_eq!(5, mock.foo(4));
    }
}

Linkshttps://crates.io/crates/mockallhttps://docs.rs/mockall

https://docs.rs/mockall

Release info

Release version: N/A

Release description N/A

Code Examples N/A

Minor update: 0.14.0 → 0.15.0

$ DOWNLOADS TREND

80.2M142.8M

$ VERSION HISTORY

v0.15.0June 28, 2026
v0.14.0November 22, 2025
v0.13.1November 17, 2024

$ LINKS

$ INSTALL

cargo add mockall

Or add to Cargo.toml: mockall = "0.15.0"