Content type expected:<application/json;charset=UTF-8> but was:<application/hal+json;charset=UTF-8>

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()));
    }


猜你喜欢

转载自blog.csdn.net/helloworld_dream/article/details/78752682
今日推荐