【发布时间】:2019-08-24 15:16:01
【问题描述】:
在集成测试中,我使用 groovy 模拟功能来模拟如下所示的服务方法:
def mock = new groovy.mock.interceptor.MockFor(PaymentService)
mock.demand.processPayment(){ a, b, c-> ['status': true, 'approved': true, 'tresponse': new TransactionResponse(amount: total.toBigDecimal(), transactionId: "4234234555", saleId: Sale.last().id, responseCode: "1", responseReasonCode: "1", responseReasonText: "approved", authorizationCode: "asdasd", paymentMethod: "CC", transactionType: "auth_capture", cardCodeResponse: "P").save(flush: true)]}
mock.use{
controller.paymentService = new PaymentService()
populateReceiptParams(total)
controller.receipt()
}
支付控制器方法receipt() 使用与authorize.net 通信的支付服务方法processPayment。所以我已经模拟了这种方法,如上所示。
运行测试时,我得到的错误如下
junit.framework.AssertionFailedError: No call to 'getMergedSale' expected at this point. Still 1 call(s) to 'processPayment' expected.
at PaymentController.cart(PaymentController.groovy:296)
at PaymentController.receipt(PaymentController.groovy:1096)
所以问题是在收据方法内部还有另一个对支付服务的调用
paymentService.getMergedSale([sessionAuth, userAuth])
这是否意味着必须在 getMergedSale 之前首先调用 processPayment 的模拟方法?我感谢任何有关此错误原因的指南。谢谢!
【问题讨论】:
标签: grails mocking integration-testing grails-2.2