How to check String in response body with mockMvc

后端 未结 12 1884
遇见更好的自我
遇见更好的自我 2020-12-02 04:02

I have simple integration test

@Test
public void shouldReturnErrorMessageToAdminWhenCreatingUserWithUsedUserName()          


        
12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 04:53

    here a more elegant way

    mockMvc.perform(post("/retrieve?page=1&countReg=999999")
                .header("Authorization", "Bearer " + validToken))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("regCount")));
    

提交回复
热议问题