0

I'm writing Spock tests for my Grails backend. I'm quite new to testing in Grails, and I'm trying to view the response to my mock request.

When I write println(response) I see this in the standard output: org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae

instead of the actual response. Is there anyway to view the contents of this mock http response instead of what is currently being printed?

alex glaze
  • 53
  • 10

1 Answers1

4

Just use Groovy's dump method:

Generates a detailed dump string of an object showing its class, hashCode and fields.

println(response.dump())

My example:

def response = new GrailsMockHttpServletResponse()
println(response.dump())

Output:

<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=[]>
Dmitry Khamitov
  • 3,061
  • 13
  • 21
  • 2
    or you could use `response.text`, `response.status`, etc from the [inherited methods](http://docs.grails.org/3.0.1/api/org/grails/plugins/testing/GrailsMockHttpServletResponse.html) – tim_yates Feb 08 '19 at 10:06