How to check String in response body with mockMvc

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

I have simple integration test

@Test
public void shouldReturnErrorMessageToAdminWhenCreatingUserWithUsedUserName()          


        
12条回答
  •  感动是毒
    2020-12-02 04:45

    Another option is:

    when:
    
    def response = mockMvc.perform(
                get('/path/to/api')
                .header("Content-Type", "application/json"))
    
    then:
    
    response.andExpect(status().isOk())
    response.andReturn().getResponse().getContentAsString() == "what you expect"
    

提交回复
热议问题