Replies: 1 comment 5 replies
-
|
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I looked where I should, at the very first part of the documentation, Getting Started.
I've seen this question at SO.
I've been puzzling over this example, and other similar examples, for about an hour. I also confirm that I've searched the discussions here.
Could someone please just tell me a couple of very basic things?
the line
#[automock]
must precede thetrait
definition... but if you have"mockall = "n.n.n.""
under[dev-dependencies]
in your cargo.toml, this will cause an "undeclared crate" error on compile ... unless you trait definition is in the tests section of the file. But if it is there, doesn't that mean you can't use it for your app code? I.e. as a basis for animpl
to be used in the app code?the example given there, i.e.
mock.expect_foo().with(predicate::eq(4)).times(1).returning(|x| x + 1);
... doesn't actually seem to prove or safeguard anything ... in Python (for example) you're using actual instances of classes and just mocking out selected parts of the functionality. If your app implementation of MyTrait in this case does something completely different to
|x| x + 1
your tests seemingly won't tell you that. I'm struggling to see what such a test in fact accomplishes.I'm 100% certain that both of these are really naive questions, but there seems to be very little along the lines of (very) low-level introductions to testing and (especially) mocking in Rust.
Beta Was this translation helpful? Give feedback.
All reactions