开发者

EasyMock methods with parameters returning void

开发者 https://www.devze.com 2023-01-17 17:23 出处:网络
My unit test framework repla开发者_C百科ces business service components with Mock objects using EasyMock.createMock(Interace).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消