spring boot junit测试时报错
解决方法:
private MediaType contentType = new MediaType("application", "hal+json", Charset.forName("UTF-8"));@Test
public void testGetUsers() throws Exception {
mockMvc.perform(get("/api/user")).andExpect(status().isOk()).andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.errcode", is(0))).andExpect(jsonPath("$.p2pdata", notNullValue()));
}
本文介绍了一个关于 SpringBoot 使用 JUnit 进行测试时遇到的问题及解决方案。问题出现在使用 mockMvc 对 /api/user 接口进行测试时,通过自定义 MediaType 解决了测试中的内容类型匹配错误。
4117

被折叠的 条评论
为什么被折叠?



