【发布时间】:2014-03-20 13:21:17
【问题描述】:
我为 REST 调用 3rd 方 api 创建了一个服务。有一个 RestBuilder 实例:
class ThirdPartyApiService{
...
private def restClient = new RestBuilder()
...
}
在测试中,我想检查 restClient.post(...) 被调用了多少次。尝试使用间谍,但没有成功。
class ThirdPartyApiServiceIntegrationSpec extends IntegrationSpec {
def thirdPartyApiService
def "test smthing"() {
setup: "prepare spies"
def restBuilderSpy = GroovySpy(RestBuilder, global: true)
when:
thirdPartyApiService.someMethod()
then:
1 * restBuilderSpy.post(* _)
}
}
它失败了
|调用太少:
1 * restBuilderSpy.post(*_)(0 次调用)
我错过了什么吗?如何实现我的目标?
【问题讨论】: