Issue 15 in mockitopp: Add functionality to clear expectations

6 views
Skip to first unread message

mock...@googlecode.com

unread,
Aug 10, 2013, 1:02:52 PM8/10/13
to mockit...@googlegroups.com
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

mock...@googlecode.com

unread,
Aug 10, 2013, 1:27:47 PM8/10/13
to mockit...@googlegroups.com

Comment #1 on issue 15 by nwon...@gmail.com: Add functionality to clear
expectations
http://code.google.com/p/mockitopp/issues/detail?id=15

It actually looks like implementing this as I've suggested would be very
difficult with the current structure. A modified version could go as
follows:

mock_object.reset(M ptr2member);
mock_object.expect(M ptr2member).when(...).reset();
mock_object.expect(M
ptr2member).when(...).reset().thenReturn(...).thenThrow(...).thenReturn(...);

I think something like this would be more straightforward to implement.

mock...@googlecode.com

unread,
Aug 10, 2013, 2:23:15 PM8/10/13
to mockit...@googlegroups.com

Comment #2 on issue 15 by nwon...@gmail.com: Add functionality to clear
expectations
http://code.google.com/p/mockitopp/issues/detail?id=15

Wrote a patch for the fix proposed in comment 1 (see attached).

Attachments:
issue15.patch 2.8 KB

mock...@googlecode.com

unread,
Aug 10, 2013, 7:05:45 PM8/10/13
to mockit...@googlegroups.com

Comment #3 on issue 15 by nwon...@gmail.com: Add functionality to clear
expectations
http://code.google.com/p/mockitopp/issues/detail?id=15

Forgot to modify the N-arity versions of dynamic_vfunction::invoke(). The
new patch has those changes, as well as some unit tests for the new
functionality.

Attachments:
issue15_with_test.patch 10.4 KB
Reply all
Reply to author
Forward
0 new messages