grails - 如何在 Grails / Spock 测试中打印响应而不是:org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae
问题描述
我正在为我的 Grails 后端编写 Spock 测试。我对在 Grails 中进行测试还很陌生,我正在尝试查看对我的模拟请求的响应。
当我编写 println(response) 时,我在标准输出中看到了这一点:org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae
而不是实际的响应。有没有办法查看这个模拟 http 响应的内容,而不是当前正在打印的内容?
解决方案
只需使用 Groovy 的转储方法:
生成显示其类、hashCode 和字段的对象的详细转储字符串。
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=[]>
推荐阅读
- css - 用户登录时如何显示密码错误消息
- lua - 我无法在 wibox.container.scroll 内的小部件上捕捉鼠标信号
- python - 即使安装了 Selenium,也会出现“ImportError:没有名为 selenium 的模块”
- javascript - 我想使用 ramda.js 按升序对日期进行排序
- javascript - Phpmailer 脚本未执行
- arrays - 在 C 中使用用户输入创建数组时出现分段错误
- eclipse - 无法在 Eclipse 中读取位于 https://ecd-plugin.github.io/update/content.xml 的存储库
- r - 绘制不同几何图形时的图例类型
- c++ - 将 Facebook Proxygen 与 Cmake 链接
- javascript - 如何在 Jupyter 笔记本中将 HTML 元素与 Python 函数链接?