mockMvc - Test Error Message

前端 未结 4 1855
小蘑菇
小蘑菇 2021-02-03 20:29

Does anybody have any tips, or does anybody know how I can test the \"error message\" returned by the HTTP response object?

@Autowired
private WebApplicationCont         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-03 21:29

    Even simpler:

    String error =  mockMvc...
        .andExpect(status().isUnauthorized())
        .andReturn().getResolvedException().getMessage();
    
    assertTrue(StringUtils.contains(error, "Bad credentials"));
    

提交回复
热议问题