#[macro_use] extern crate mock; trait SomeTrait { fn first(&self, Vec) -> String; fn string(&mut self, i32, i32, i32, i32) -> &'static str; fn result(&self) -> Result; fn void(&self); } #[test] fn it_works() { let x = mock!(SomeTrait); mock!(x.first(Vec) -> String { "success".into() }); mock!(x.string(i32, i32, i32, i32) -> &'static str { "static" }); mock!(x.result() -> Result { let ok = "ok".into(); Ok(ok) }); mock!(x.void() -> ()); let y = mock!(SomeTrait); mock!(y.result() -> Result { Err(()) }); assert_eq!("success", &x.first(vec![])); assert_eq!("static", x.string(0, 0, 0, 0)); assert_eq!("ok".to_string(), x.result().unwrap()); assert_eq!(Err(()), y.result()); }