Visibility with mock!
#295
Answered
by
asomers
jprenaudet
asked this question in
Questions
-
I'm trying to use the "MockTrait" from another module in the same crate. Here is a small code so you can reproduce : mod auto {
use mockall::*;
#[automock]
pub trait MyAutoTrait {
fn test(&self) -> i32;
}
}
mod manuel {
use mockall::*;
pub trait MyManuelTrait {
fn test(&self) -> i32;
}
mock! {
pub MockMyManuelTrait {}
impl MyManuelTrait for MockMyManuelTrait {
fn test(&self) -> i32;
}
}
}
use auto::*;
use manuel::*;
fn func_to_test_auto(t: &dyn MyAutoTrait) -> i32 {
t.test()
}
fn func_to_test_manuel(t: &dyn MyManuelTrait) -> i32 {
t.test()
}
fn main() {
let mut mock = MockMyAutoTrait::new();
mock.expect_test().return_const(5);
let test = func_to_test_auto(&mock);
println!("test: {}", test);
let mut mock2 = MockMyManuelTrait::new();
mock2.expect_test().return_const(6);
let test = func_to_test_manuel(mock2);
println!("test: {}", test);
}
|
Beta Was this translation helpful? Give feedback.
Answered by
asomers
Jun 22, 2021
Replies: 1 comment 1 reply
-
When you use mock! {
pub MyManuelTrait {}
impl MyManuelTrait for MyManuelTrait {
fn test(&self) -> i32;
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jprenaudet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you use
mock!
, just type the name of the struct that you're trying to mock. Don't add a leadingMock
; Mockall will do that for you. So do it like this: