Java Junit mockMVC中的模拟空对象
我试图将null作为JUnit mockMvc的内容类型传递,但失败了Java Junit mockMVC中的模拟空对象,java,spring-boot,mockmvc,Java,Spring Boot,Mockmvc,我试图将null作为JUnit mockMvc的内容类型传递,但失败了 Object obj =null; MvcResult result = mockMvc.perform(post("/mgr/v1/processEvent") .contentType(MediaType.APPLICATION_JSON) .content(String.valueOf(obj)) .accept(MediaType.APPLICATION_JSON))
Object obj =null;
MvcResult result = mockMvc.perform(post("/mgr/v1/processEvent")
.contentType(MediaType.APPLICATION_JSON)
.content(String.valueOf(obj))
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().is4xxClientError()).andReturn();
它不会进入控制器调用
请帮助不要使用
String.valueOf(null)代码>。Null被解释为一个字符数组,它会导致NullpointerException
。只需使用空字符串或保留完整的行
MvcResult result = mockMvc.perform(post("/mgr/v1/processEvent")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().is4xxClientError()).andReturn();
不要使用String.valueOf(null)代码>。Null被解释为一个字符数组,它会导致NullpointerException
。只需使用空字符串或保留完整的行
MvcResult result = mockMvc.perform(post("/mgr/v1/processEvent")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().is4xxClientError()).andReturn();
下次,请添加有关代码失败方式的更多信息(如堆栈跟踪)。下次,请添加有关代码失败方式的更多信息(如堆栈跟踪)。