gpt4 book ai didi

testing - 使用具有动态行为的 EasyMock 模拟 void 函数

转载 作者:行者123 更新时间:2023-11-28 20:15:58 25 4
gpt4 key购买 nike

我需要使用 EasyMock 模拟一个 void 函数,以便第一次调用返回异常,而下一次调用成功。

例如:

this.myObject.move((String) EasyMock.anyObject());
EasyMock.expectLastCall().once().andThrow(new RetryableDependencyException());
EasyMock.expectLastCall().once();

但这行不通。

最佳答案

这是行不通的,因为第二个 expectLastCall() 找不到任何调用。

你试过这个吗:

this.myObject.move((String) EasyMock.anyObject());
EasyMock.expectLastCall().once().andThrow(new RetryableDependencyException());
this.myObject.move((String) EasyMock.anyObject());
EasyMock.expectLastCall().once();

我知道它有点冗长,但它应该让你排序 :)

关于testing - 使用具有动态行为的 EasyMock 模拟 void 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12645691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com