aspose file tools*
The moose likes Testing and the fly likes Unable to fully utilize EasyMock. Not compliance with Test Driven Approach. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Unable to fully utilize EasyMock. Not compliance with Test Driven Approach." Watch "Unable to fully utilize EasyMock. Not compliance with Test Driven Approach." New topic
Author

Unable to fully utilize EasyMock. Not compliance with Test Driven Approach.

Ravi C Kota
Ranch Hand

Joined: Jan 29, 2008
Posts: 61
Hi All,

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.

For eg,



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

EasyMock.expect(b.execute()).andReturn()
EasyMock.expect(c.execute()).andReturn()
EasyMock.expect(d.execute()).andReturn()

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





Thanks & Regards, Ravi C.Kota
SCJP 5.0, OCDJWS 5.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to fully utilize EasyMock. Not compliance with Test Driven Approach.