Assertion error: No value for JSON Path in JUnit test

You are asserting that your response contains a field name with value Bordeaux.

You can print your response using this.webClient.perform(...).andDo(print()).


I was getting same problem.

Solution :

Use .andReturn().getResponse().getContentAsString();, your response will be a string. My response was:

{"url":null,"status":200,"data":{"id":1,"contractName":"Test contract"}

When I was trying to do .andExpect(jsonPath("$.id", is(1))); there was an error: java.lang.AssertionError: No value for JSON path: $.id

To fix it, I did .andExpect(jsonPath("$.data.id", is(1))); and it works because id is a field in data.


Most likely jsonPath interprets the body of your file as a list and this should do the trick (mind the added square brackets as list accessors):

.andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("Bordeaux"))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].cost").value(10.55));