此时没有预期的呼叫.仍然调用 1 次预期错误



在集成测试中,我使用 groovy mock 功能来模拟如下所示的服务方法:

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()
}

支付控制器方法收据()使用与 authorize.net 通信的支付服务方法进程付款。所以我模拟了这种方法,如上所示。

运行测试时,我得到的错误如下

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的模拟方法?我感谢有关此错误原因的任何指南。谢谢!

那么这是否意味着模拟方法即 处理付款 必须 在获得合并销售之前先调用?

不一定,没有。 这确实意味着您需要提供getMergedSale的模拟实现。

最新更新