You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly, respect due on this amazing crate. Has made testing a dream for projects I've been working on.
I was wondering if there would be anyway to construct Mocks with some kind of identifier? Or the some way to add contextual information to expectations? I realise anything with a member variables is typically un-mock-like, but for larger integration tests with tons of mocks flying around I often am left scratching my head when something falls over. For example, say I have 20-30 MockThing instances wrapped in MyContainer which performs a series of operations on them by calling .foo(x, y) and each MockThing::foo has custom expectations defined on it... When one of those expectations fails, I get a panic like:
thread 'tests::my_container' panicked at 'MockThing::foo(?, ?): No matching expectation found'
Which is a pain to diagnose.. But, if we had some contextual information added to the Mock or Expectation, then it would make it much easier to fix.
Thanks
The text was updated successfully, but these errors were encountered:
I'm glad you like it! As for your question, one thing immediately comes to mind: you'll get better error messages if you enable the nightly crate feature. As its name suggests, that requires a nightly compiler. Or, if you use the latest unreleased crate from the git master branch, you'll also get better error messages even without the nightly feature.
As for some kind of mock id, I can see how that would be useful for your case. Other than panic messages, are there any other places where you think it might be helpful?
nightly is only an option for my personal projects unfortunately, work requirements are stricter. But, good to know I can pull tip of main to get better error messages.
In addition to improved panics, it could be useful to have a derived Display implementation that output this user defined contextual info so you could print whole test objects prior to running whatever logic causes a panic
Hello!
Firstly, respect due on this amazing crate. Has made testing a dream for projects I've been working on.
I was wondering if there would be anyway to construct Mocks with some kind of identifier? Or the some way to add contextual information to expectations? I realise anything with a member variables is typically un-mock-like, but for larger integration tests with tons of mocks flying around I often am left scratching my head when something falls over. For example, say I have 20-30
MockThing
instances wrapped inMyContainer
which performs a series of operations on them by calling.foo(x, y)
and eachMockThing::foo
has custom expectations defined on it... When one of those expectations fails, I get a panic like:thread 'tests::my_container' panicked at 'MockThing::foo(?, ?): No matching expectation found'
Which is a pain to diagnose.. But, if we had some contextual information added to the Mock or Expectation, then it would make it much easier to fix.
Thanks
The text was updated successfully, but these errors were encountered: