spring项目进行junit测试出现如下错误
java.lang.AssertionError: Status expected:<200> but was:<405> at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60) at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89) at org.springframework.test.web.servlet.result.StatusResultMatchers$5.match(StatusResultMatchers.java:549) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:141http stauts状态返回的是405
405 - 用来访问本页面的 HTTP 谓词不被允许(方法不被允许)要调查controller类中的方法请求是get还是post
@RequestMapping(value = "/msg/update" ,method = RequestMethod.GET)如何controller类请求设置为get那么测试类中也要使用get
@Test public void testUpdateMsg() throws Exception { mockMvc.perform(get("/ms/update", "json").accept(MediaType.APPLICATION_JSON) .param("id", "1") .param("title", "abc") ) .andDo(print()) .andExpect(status().isOk()); }如果controller求情设置为post那么junit测试代码应该用post("/ms/update", "json")