$ mockall
v0.15.0A powerful mock object library for Rust.
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));
}
}
Links • https://crates.io/crates/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
$ VERSION HISTORY
$ LINKS
$ INSTALL
cargo add mockallOr add to Cargo.toml: mockall = "0.15.0"