when / verify interaction

349 views
Skip to first unread message

James Cooper

unread,
Jul 8, 2010, 11:17:23 AM7/8/10
to mockito-python
Hello again,

I am using verifyNoMoreInteractions() to ensure strict checking of my
mock.

I've noticed that when I do this I have to duplicate all my "when()"
calls with "verify()" calls after I run the class under test.

This smells like duplicated code. Would it be bad to have
verifyNoMoreInteractions() consider all when() calls to be mandatory,
and automatically include them.

I've created a basic example here:

http://pastebin.com/raw.php?i=kDxqjW3Z

The test class has two methods that do the same thing.

testOnlyGeneratesReportForCustomersWithWidgetsFailure - fails
because I don't include verify() calls for all my when() calls
testOnlyGeneratesReportForCustomersWithWidgetsSuccess - passes
because I include 3 extra verify calls that duplicate my when calls


It seems that verifyNoMoreInteractions() could automatically verify
that my when() expectations were satisfied and fail if they weren't.
Would anyone be surprised by that behavior?

thank you

-- James

Serhiy Oplakanets

unread,
Jul 8, 2010, 12:24:55 PM7/8/10
to mockito-python
Hi James,
I see your point here. That's probably the question almost everybody
raise when trying mockito first time after having some experience with
"classic", expectation based frameworks. I believe I can't explain it
better then Szczepan did at his blog-post --
http://monkeyisland.pl/2008/07/12/should-i-worry-about-the-unexpected/

Hope it'll explain you why normally you should NOT "worry about
unexpected".

Serhiy

James Cooper

unread,
Jul 8, 2010, 12:31:04 PM7/8/10
to mockito-python
Hi there,

That's a very good blog entry and you are correct -- I'm coming from
Java using EasyMock/jMock which use the record/run/verify model.

BTW, mockito and lettuce (http://lettuce.it) are working very well
together for me. I suggest lettuce to anyone looking to do BDD in
python.

-- James

On Jul 8, 9:24 am, Serhiy Oplakanets <ser...@oplakanets.com> wrote:
> Hi James,
> I see your point here. That's probably the question almost everybody
> raise when trying mockito first time after having some experience with
> "classic", expectation based frameworks. I believe I can't explain it
> better then Szczepan did at his blog-post --http://monkeyisland.pl/2008/07/12/should-i-worry-about-the-unexpected/

Serhiy Oplakanets

unread,
Jul 8, 2010, 12:39:58 PM7/8/10
to mockito-python
Cool,
I was introduced to lettuce about 2 weeks go and still haven't got any
time to try it.
Speaking about BDD, do you think mockito-python needs BDD module? Like
in older mockito (http://mockito.googlecode.com/svn/tags/latest/
javadoc/org/mockito/BDDMockito.html) ?

I was thinking of adding some BDD module, like:
>>> from mockito import mock
>>> from mockito.bdd import given
>>> dummy = mock()
>>> given(dummy).foo().willReturn("bar")
>>> dummy.foo()

James Cooper

unread,
Jul 9, 2010, 10:08:26 AM7/9/10
to mockito-python
Hi there,

I like the UNIX philosophy of doing one little thing well so you can
combine different pieces together as you wish.

So my vote would be to keep BDD features out of mockito and instead
show examples of how it could be used together with existing BDD
frameworks.

-- James
Reply all
Reply to author
Forward
0 new messages