【发布时间】:2016-02-13 01:59:56
【问题描述】:
我已经写了一个测试,之前它成功了,但现在我得到一个 AssertionError: No value for JSON Path。
@Test
public void testCreate() throws Exception {
Wine wine = new Wine();
wine.setName("Bordeaux");
wine.setCost(BigDecimal.valueOf(10.55));
new Expectations() {
{
wineService.create((WineDTO) any);
result = wine;
}
};
MockMultipartFile jsonFile = new MockMultipartFile("form", "", "application/json", "{\"name\":\"Bordeaux\", \"cost\": \"10.55\"}".getBytes());
this.webClient.perform(MockMvcRequestBuilders.fileUpload("/wine").file(jsonFile))
.andExpect(MockMvcResultMatchers.status().is(200))
.andExpect(MockMvcResultMatchers.jsonPath("$.name").value("Bordeaux"))
.andExpect(MockMvcResultMatchers.jsonPath("$.cost").value(10.55));
}
我得到的错误是:
java.lang.AssertionError: No value for JSON path: $.name, exception: No results path for $['name']
我不明白它没有得到什么或缺少什么。
【问题讨论】:
标签: java json junit spring-mvc-test