【问题标题】:No call to expected at this point. Still 1 call(s) to expected error此时没有预期的呼叫。仍有 1 次调用预期错误
【发布时间】: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


    【解决方案1】:

    这是否意味着必须模拟的方法是 processPayment 在 getMergedSale 之前先调用?

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

    【讨论】:

    • 谢谢。那么是否应该模拟所有可能在支付服务上调用的方法?
    • 一般来说是的。
    • 如果您也可以调查此问题,我将不胜感激。 stackoverflow.com/questions/55508397/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 2020-05-03
    • 1970-01-01
    相关资源
    最近更新 更多