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"
35
35
Then use it like this:
36
36
37
37
``` rust
38
- use mockall :: * ;
39
- use mockall :: predicate :: * ;
40
- #[automock]
38
+ #[cfg(test)]
39
+ use mockall :: {automock, mock, predicate :: * } ;
40
+ #[cfg_attr(test, automock) ]
41
41
trait MyTrait {
42
42
fn foo (& self , x : u32 ) -> u32 ;
43
43
}
44
44
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
+ }
51
57
```
52
58
53
59
See the [ API docs] ( https://docs.rs/mockall ) for more information.
You can’t perform that action at this time.
0 commit comments