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