gpt4 book ai didi

unit-testing - 使用Spock测试的关于新类的Grails单元测试

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

我的方法是:

def client = new SOAPClient("http://...")
def response = client.send(
"""<?xml version='1.0' encoding='UTF-8'?>
<soap-env:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
<soap-env:Body>
<GetFoo>bar</GetFoo>
</soap-env:Body>
</soap-env:Envelope>"""
)
return response.httpResponse.statusCode

SOAPClient是Grails的插件。

因此,在单元测试中,如何模拟SOAPClient及其发送方法?

最佳答案

def client = Mock(SOAPClient)
client.send(_) >> response

当然,您需要首先创建所需的响应对象。

关于unit-testing - 使用Spock测试的关于新类的Grails单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21772274/

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