我正在为Grails后端编写Spock测试。我对在Grails中进行测试非常陌生,并且正在尝试查看对模拟请求的响应。
当我写println(response)时,我在标准输出中看到了这个:org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae
而不是实际回应。无论如何,是否有机会查看此模拟http响应的内容,而不是当前正在打印的内容?
最佳答案
只需使用Groovy的dump方法:
Generates a detailed dump string of an object showing its class, hashCode and fields.
println(response.dump())
我的示例:
def response = new GrailsMockHttpServletResponse()
println(response.dump())
输出:
<org.grails.plugins.testing.GrailsMockHttpServletResponse@6a79c292 outputStreamAccessAllowed=true writerAccessAllowed=true characterEncoding=ISO-8859-1 charset=false content= outputStream=org.springframework.mock.web.MockHttpServletResponse$ResponseServletOutputStream@21a947fe writer=null contentLength=0 contentType=null bufferSize=4096 committed=false locale=en_US cookies=[] headers=[:] status=200 errorMessage=null forwardedUrl=null includedUrls=[]>
关于grails - 您如何在Grails/Spock测试中而不是在org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae中打印响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54585000/