How to print response object content in JUnit test case

1k Views Asked by At

I am writing a Junit test case which is running successfully. I want a assert to check if response content is not null.

enter image description here

I am able to see the content in response object, but not getting how to print this content or put a assert on this to check for null.

After adding json-path jar I am getting this error on line no 132, it gets terminated:

Any help would be really appreciated.

enter image description here

1

There are 1 best solutions below

0
tricksSpecialist On

from the documentation of mvcResult.getResponse() where getResponse() says: the response, never null. So, i think you can use the follwoing:

assertNotNull(mvcResult.getResponse());

after that you can use whatever you want like:

assertEquals("your return", mvcResult.getResponse().getContentAsString());