Unit Test Spring MVC Rest Service: MockMVC, JUnit, Mockito

You may also like...

  • Mahi

    Nice article. The code is working as expected as well. But the only issue I found is “UserControllerIntegrationTest” class is throwing exceptions. Is there any additional configuration needed to run the integration tests?

    org.springframework.web.client.HttpClientErrorException: 404 Not Found

    test_update_user_success(com.memorynotfound.test.UserControllerIntegrationTest) Time elapsed: 0.138 sec <<< ERROR!
    org.springframework.web.client.HttpClientErrorException: 403 Forbidden

  • Vincent Cheng

    A nice tutorial, but I have a question, in my User class, I have a dateOfBirth field with reference type is LocalDate(from joda-time), what is the correct syntax for testing that field? I try “.andExpect(jsonPath(“$[0].dateOfBirth”, is(new LocalDate(1990, 12, 1))))”, but I am getting “Expected: is
    but: was ”

    Thank you for your help

    • Vincent Cheng

      OK, I found the solutions, I need to write the custom JsonSerializer class to Serialize the date I want