May be I misunderstand the concept of mock object. I saw some post in stackoverflow for understanding when I should use mock object. Really I don't know when must I use mock object. I give an example of book Growing Object-Oriented Software, Guided by Tests:
context.checking(new Expectations() {{
oneOf (turtle).turn(45);
}});
Usage is simple:
Is turn
method executed only once? If is true test will be pass. If not test will be failed. This is my understanding of mock object.
Martin Fowler in Mocks Aren't Stubs said:
Mocks use behavior verification, where we instead check to see if the SUT made the correct calls on the collaborator.
But my question is why we need verify behavior of collaborator object (in this case turtle
) if we want to unit test SUT?