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 number of important elements to note include the following:

  • get("/welcome-model-view"): This executes the get request to the specified URL.
  • view().name("welcome"): This uses ResultMatcher to check whether the View name returned is as specified.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset