This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Recently in one of my projects, I started using EasyMock framework for mocking the objects. I'm not using EasyMock extensions, so I'm currently not able to mock static or private methods. Well I'm not complaining about it now, as I knew I need to use EasyMock extension. But the way I'm mocking the objects seem to be stupid to me and clearly it does not follow Test Driven approach. Please guide me on proper usage of the EasyMock or other better framework.
Currently, I'm mocking every step of execution (including the sequence of execution) using EasyMock based on the actual implementation of the class under test. This seems so wrong to me. If I had to change the sequence of execution, but keeping the net outcome as same, still I need to change my tests. I knew that I'm doing something wrong here.
As you see, execute() method of ClassA, is invoking execute() methods of classB, classC, ClassD and some more processing, independent of these executes. Also, the sequence of execution also does not really matter. If I need to test execute() of A, I can mock B, C,D and write something like
But what I'm currently doing here is I need to execute these steps in the same sequence they are being executed in actual class. The worst is, I need to do the same even for other processing that goes in parallel.
This is apparently not a test driven approach and rather I would call it as code driven testing. So I wanted to know, if this is a limitation of EasyMock or a limitation of my knowledge in EasyMock. If it is really a limitation with EasyMock, then is there any better framework I can use, where I can create all mocks objects and methods upfront and do not bother about placing them in exact sequence.
Can a good pointer for examples be provided for EasyMock or for other such frameworks?
Thanks & Regards, Ravi C.Kota
SCJP 5.0, OCDJWS 5.0