Spock 测试框架:模拟与存根的深入解析
1. 信用卡两步收费测试示例
1.1 代码示例
Putting it all together: credit card charging in two steps
then: "inventory is checked"
with(inventory) {
2 * isProductAvailable(!null , 1) >> true
_ * isEmpty() >> false
}
then: "credit card is charged"
1 * creditCardSevice.capture({myToken -> myToken.endsWith("sample")},
customer) >> CreditCardResult.OK
charged
0 * _
1.2 代码解释
- 库存检查 :使用
with(inventory)方法将库存交互进行分组。2 * is
超级会员免费看
订阅专栏 解锁全文
33

被折叠的 条评论
为什么被折叠?



