目前尚无人致电。仍然有1个呼叫预期错误

时间:2019-04-03 07:22:14

标签: grails mocking integration-testing grails-2.2

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

}

付款控制器方法receive()使用与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的调用

paymentService.getMergedSale([sessionAuth, userAuth])

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

1 个答案:

答案 0 :(得分:1)

  

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

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