【发布时间】:2018-01-18 16:50:44
【问题描述】:
是否可以在Spock中获取mocked方法的调用次数?我想测试该方法是否被调用了特定次数,但是每秒返回的值应该不同。下面的伪代码应该更具体地说明我想要什么:
void "My idea of a test" {
when:
...
then:
10 * someService(_) >> {
return theNumberOfTheCall % 2 ? SOME_VALUE : null // theNumberOfTheCall should illustrate my purpose
}
// so the service will return [null, SOME_VALUE, null, SOME_VALUE, null ...]
}
【问题讨论】: