I stumbled over this article yesterday: A neat and short description of Mock objects and a motivation how Mock objects in general and Mocking frameworks can support (unit) testing particularly with classes that have dependencies. I like this very short introduction because the concept of Mock-objects is actually not so difficult to understand but the need for Mock-frameworks is not so easy to grasp.
If the basic idea is understood the documentation of frameworks like JMock can kick in and do the rest ;-)
Addition: Thanks to the comment of reader Touku who recommended the article from Martin Fowler: Mocks Aren't Stubs.
Yes, mocks are nice and valuable tools with (unit) testing.
ReplyDeleteI personally found it good to understand the difference between mocks and stubs (valuable testing methods for about the same purpose but with a different approach). Martin Fowler has a good article on the topic: Mocks Aren't Stubs
By the way, I find Mockito even easier to use as JMock and Easy Mock.
ReplyDeleteSee this example:
Gehalt g = new Gehalt();
Krk kkasse = mock(Krk.class); stub(kkasse.getKVersich()).toReturn(300.0);
g.setKrk(kkasse);
// then use g
And this covers 90% of all mock need I have.
Best
Stefan Edlich