File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -35,19 +35,25 @@ mockall = "0.6.0"
3535Then use it like this:
3636
3737``` rust
38- use mockall :: * ;
39- use mockall :: predicate :: * ;
40- #[automock]
38+ #[cfg(test)]
39+ use mockall :: {automock, mock, predicate :: * } ;
40+ #[cfg_attr(test, automock) ]
4141trait MyTrait {
4242 fn foo (& self , x : u32 ) -> u32 ;
4343}
4444
45- let mut mock = MockMyTrait :: new ();
46- mock . expect_foo ()
47- . with (eq (4 ))
48- . times (1 )
49- . returning (| x | x + 1 );
50- assert_eq! (5 , mock . foo (4 ));
45+ #[cfg(test)]
46+ mod tests {
47+ #[test]
48+ fn mytest () {
49+ let mut mock = MockMyTrait :: new ();
50+ mock . expect_foo ()
51+ . with (eq (4 ))
52+ . times (1 )
53+ . returning (| x | x + 1 );
54+ assert_eq! (5 , mock . foo (4 ));
55+ }
56+ }
5157```
5258
5359See the [ API docs] ( https://docs.rs/mockall ) for more information.
You can’t perform that action at this time.
0 commit comments