verifyNoMoreInteractions to ignore realized stubbings by default

11 views
Skip to first unread message

Szczepan Faber

unread,
Jul 31, 2016, 10:33:09 PM7/31/16
to mocki...@googlegroups.com
Hey!

Currently verifyNoMoreInteractions/verifyZeroInteractions forces the
user to verify stubbed invocations. This sometimes leads to awkward
tests, where same interaction is mentioned in the test _twice_, once
for stubbing, once for verification. Duplication/repetition in tests
is not ideal.

I was wondering if this behavior is actually good for our users.
Wouldn’t it be better if verifyNoMoreInteractions() automatically
accepted stubs that were ‘used’ during test execution, e.g:

when(foo.bar()).thenReturn(1); //stubbing
int x = foo.bar(); //using the stubbing
verifyNoMoreInteractions(foo); //passes! the stubbing was used so it’s
implicitly verified

Currently, this behavior can be “sort of” emulated by doing:

verifyNoMoreInteractions(ignoreStubs(foo));

However, above ignores all stubs, regardless if the stubbing was
actually realized in tests or not.

Question: Putting the compatibility aspect aside, what’s better
behavior for our users?

Cheers!
--
Szczepan Faber
Founder @ mockito.org | Twitter @ szczepiq
Author @ https://www.linkedin.com/today/author/6016386

Tim van der Lippe

unread,
Aug 2, 2016, 10:18:40 PM8/2/16
to mocki...@googlegroups.com

I am probably misunderstanding the usecase, could you provide the full two test cases? One with the old and undesirable behavior and the new test with the improved usage. Currently cant seem to wrap my head around the idea just yet.


--
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito-dev...@googlegroups.com.
To post to this group, send email to mocki...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito-dev.
For more options, visit https://groups.google.com/d/optout.

Szczepan Faber

unread,
Aug 2, 2016, 11:43:55 PM8/2/16
to mocki...@googlegroups.com
Sure thing.

Szczepan Faber

unread,
Aug 21, 2016, 6:53:19 PM8/21/16
to mocki...@googlegroups.com
I couldn't come up with the use case that convinces me. Let's move on
and maybe revisit :)
Reply all
Reply to author
Forward
0 new messages