EasyMock添加行为

EasyMock使用expect()方法或expectLassCall()方法添加一个功能,一个模拟对象。请看下面的代码片段。

1
//add the behavior of calc service to add two numbersEasyMock.expect(calcService.add(10.0,20.0)).andReturn(30.00);

这里,我们已经指示EasyMock,行为添加10和20到calcService的添加方法并作为其结果,到返回值30.00

在这个时间点上,模拟简单记录的行为,但它本身不作为一个模拟对象。调用回放后,按预期工作。

1
//add the behavior of calc service to add two numbersEasyMock.expect(calcService.add(10.0,20.0)).andReturn(30.00);//activate the mock//EasyMock.replay(calcService);

不需要EasyMock.Replay()的示例

需要EasyMock.Replay()的示例

原文地址:https://www.cnblogs.com/hane/p/7299389.html