-
I have a file I have seen #219, but it seems the suggestion there is to rewrite all function signatures in the same place I do My only option seems to be to introduce an internal module Is this the only way? Or is there a way to automock |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You could do something like this in somefile.rs: // somefile.rs
use cfg_if::cfg_if;
use mockall::automock;
#[automock]
pub mod inner {
pub fn foo(x: u32) -> u32 {...}
}
cfg_if! {
if #[cfg(test)] {
pub use mock_inner::foo;
} else {
pub use inner::foo;
}
} That approach has the advantage that you don't have to modify any other file. Alternatively, if you really don't want to modify somefile.rs, you could create mock_somefile.rs which repeats the function definitions like this, and then use // mock_somefile.rs
use mockall::automock;
#[automock]
pub mod inner {
pub fn foo(x: u32) -> u32 {unimplemented!()}
} |
Beta Was this translation helpful? Give feedback.
You could do something like this in somefile.rs:
That approach has the advantage that you don't have to modify any other file. Alternatively, if you really don't want to modify somefile.rs, you could create mock_somefile.rs which repeats the function definitions like this, and then use
#[double]
in the other files