gpt4 book ai didi

grails - 目前尚无人调用。仍然有1个调用预期错误

转载 作者:行者123 更新时间:2023-12-02 15:16:57 24 4
gpt4 key购买 nike

在集成测试中,我正在使用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()

}

支付 Controller 方法receive()使用与authorize.net通信的支付服务方法processPayment。所以我已经 mock 了这种方法,如上所示。

运行测试时,我得到的错误如下
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的调用
paymentService.getMergedSale([sessionAuth, userAuth])

那么这是否意味着必须在getMergedSale之前首先调用模拟方法processPayment?感谢您提供有关此错误原因的任何指导。谢谢!

最佳答案

So does this mean that the mocked method which is processPayment must be called first before getMergedSale?



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

关于grails - 目前尚无人调用。仍然有1个调用预期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55489285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com