- Mastering Spring 5.0
- Ranga Rao Karanam
- 59字
- 2021-07-02 22:12:11
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