EasyMock methods with parameters returning void
My unit test framework repla开发者_C百科ces business service components with Mock objects using EasyMock.createMock(Interace).
These components are accessed several layers down in the class under test so I don't wish to modify either the interface definition nor the class undertest.
I then use EasyMock.expect(...) to drive the behavoir of the collaborating objects. This works great as long as the methods don't return void.
How can I drive the behavior when there are void results. Ie.
EasyMock.expect(object.Method( EasyMock.isA(arg1) ).andAnswer( new IAnswer()){
public void anser(){
... do seomething meaningful with arg1...
}).anyTimes();
You can use expectLastCall().andReturn("something");
.
You don't mention which version of EasyMock you're using, but I think this feature has been around for a while anyway.
Read more in the documentation.
精彩评论