繁体   English   中英

Grails单元测试使用Spock测试新的一些类

[英]Grails unit test about new some class using Spock testing

我的方法是:

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及其send方法?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM