Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 15 by
nwon...@gmail.com: Add functionality to clear expectations
http://code.google.com/p/mockitopp/issues/detail?id=15
This is an enhancement request.
I've had some use cases where I need to set a block of expectations on a
mock_object for a set of unit tests where each unit test wants to use a
default set of values while specializing on only one. Currently,
mock_object provides no mechanism to override or clear previously-set
expectations, so it's not possible to set the default expectations in the
setup() function of the unit test framework and then cleanly override the
default for any single function in the unit test body itself. There are
some workarounds, but they clutter the code and make the flow and intent
less clear.
I've thought of a few expressions that would be useful to support:
1) Reset all expectations for a given function
2) Reset all expectations for a given function with specific matching
args (i.e. args to when())
3) Reset all expectations for a given function with specific matching
args and chain new expectations (thenReturn(), thenThrow()) in the same
call iteratively
The semantics for one possible solution:
// Reset all previously set expectations for ptr2member.
// Alternative names: disregard(), cancel(), reject()
mock_object::reset(M ptr2member);
// Reset all previously set expectations for ptr2member calls
// where args match those defined in when().
mock_object::reset(M ptr2member).when(...);
// Reset previously set expectations and set new expectations in the
same call iteratively
mock_object::reset(M
ptr2member).when(...).thenReturn(...).thenThrow(...).thenReturn(...);
Any comments on these semantics or the general solution?
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings