Attribute Macro moq::automock

source · []
#[automock]
Expand description

Macro that provides mock struct generating that implements trait

Example

#[moq::automock]
trait Trait {
    fn func(&self, arg: i32) -> String;
}

#[test]
fn test_ok() {
    let mock = TraitMock::new()
        .expect_func(|arg: i64| {
            assert_eq!(arg, 42);
            format!("Hello, {}", arg)
        })
        .expect_func(|arg: i64| {
            assert_eq!(arg, -1);
            format!("Hello again, {}", -1)
        });
     
    mock.func(42);
    mock.func(-1);
}