Writing the Test method

The complete test method is shown as follows:

    @Test     public void testWelcomeView() throws Exception {       this.mockMvc       .perform(get("/welcome-view")       .accept(MediaType.parseMediaType(       "application/html;charset=UTF-8")))       .andExpect(view().name("welcome"));     }

A few important things to note are as follows:

  • get("/welcome-model-view"): This executes the get request to the specified URL
  • view().name("welcome"): This uses Result Matcher to check whether the view name returned is as specified

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.