[mockito] States vs. InOrder verification

26 views
Skip to first unread message

James Carr

unread,
Apr 24, 2010, 4:13:09 PM4/24/10
to moc...@googlegroups.com
I recently finished up Steve and Nat's book and on thing of interest
that he introcduced was using the concept of states
(http://www.jmock.org/states.html) rather than verifying interactions
occur in order. Essentially, when different interactions occur you can
say that the object is in a certain "state" and then verify that
state. This makes a lot of sense for the same reasons I never ever use
the InOrder verifications in mockito... in my experience InOrder
verifications either indicate some very procedural logic or in the
cases where it might seem to be relevant the tests produced with it
are often very brittle.

After seeing several examples of "state" based verification, I like it
and I keep thinking... how could we introduce a similar feature in
mockito? As another method tacked on to givne/when maybe? Something
like

when(foo.pushDown()).thenStateIs("down");
when(foo.pushDown()).thenStateIs("up");

or

given(foo.pushDown()).thenStateIs("down");
given(foo.pushDown()).thenStateIs("up");

Just a thought.


Thanks,
James

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.

Chris Bartling

unread,
Apr 24, 2010, 9:08:09 PM4/24/10
to moc...@googlegroups.com
On a related note, if you haven't had a chance to read Steve and Nat's book, it quite good.  One of my favorites for 2009.  Well worth the read.



Regards,

-- chris --  

szczepiq

unread,
Apr 27, 2010, 10:46:52 AM4/27/10
to moc...@googlegroups.com
Hey


>>
when(foo.pushDown()).thenStateIs("down");
when(foo.pushDown()).thenStateIs("up");

I'm not sure how it fits Mockito. You would need some verification mechanism afterwards, like verifyStates(); Also you need some constraining mechanism for defining states :) like when(foo.pushDown()).inState("down").thenStateIs("up");

It would be good to see a real example where it is useful.

Cheers!
Szczepan
Reply all
Reply to author
Forward
0 new messages