grails - 您如何在Grails/Spock测试中而不是在org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae中打印响应

标签 grails println groovy-console

我正在为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/

相关文章:

json - 从控制台到导入Grails转换器的挣扎

java - 在groovyConsole中导入Spring框架抛出错误

string - 什么函数用于格式化/替换 Grails/Groovy 中字符串中的 {0} {1} 参数?

grails - Grails:扩展和嵌入域类有什么区别?

groovy - 从 JSON ARRAY(映射列表)中查找/过滤具有特定键值对的列表

Java scan.nextLine() 只等待int用户输入的用户输入;不等待字符串用户输入

java - Gradle总是从任何任务执行println

unit-testing - 单元测试 Grails Controller 链接

grails - 在Spock Framework中继承。我想在多个规范中重用测试用例

java - 为什么初始化字符串后得到 null?