我环顾四周,尝试了不同的事情无济于事.互联网上的例子很少,恕我直言很简单.我的用例:
(下面的'itocNetworkHandler'是模拟)
when: "we're doing stuff"
StandardResponse response = cms.doCardStuff("123", "111", order)
....
then: "we get proper calls and response object"
1 * cms.itocNetworkHandler.doNetworkCall(
{ it instanceof ReplacementRequestRecord
}, StandardResponseRecord.class) >> record
Run Code Online (Sandbox Code Playgroud)
我想将参数('it')存储到mock上的"doNetworkCall"中.
我想要参数的原因是因为我正在测试的对象应该接受我的参数,做东西,创建一个新对象并将那个传递给我的模拟.我想确保创建的对象看起来像它应该的样子.
指针非常赞赏.
Pet*_*ser 43
您可以按如下方式捕获参数:
// must be declared before when-block (or inside Specification.interaction {})
def captured
when:
...
then:
1 * mock.doNetworkCall(...) >> { record, recordClass ->
// save the argument
captured = record
...
}
// use the saved argument
captured == ...
Run Code Online (Sandbox Code Playgroud)
也就是说,通常有一个更简单的解决方案,例如在参数约束中检查预期记录(例如...doNetworkCall( { it == ... } )
).
归档时间: |
|
查看次数: |
8515 次 |
最近记录: |