![Mastering Spring 5.0](https://wfqqreader-1252317822.image.myqcloud.com/cover/64/36701064/b_36701064.jpg)
上QQ阅读APP看书,第一时间看更新
Writing the Test method
The complete Test method is shown in the following code:
@Test
public void basicTest() throws Exception {
this.mockMvc
.perform(
get("/welcome-model-map")
.accept(MediaType.parseMediaType
("application/html;charset=UTF-8")))
.andExpect(model().attribute("name", "XYZ"))
.andExpect(view().name("welcome-model-map"));
}
A few important things to note:
- get("/welcome-model-map"): Execute get request to the specified URL
- model().attribute("name", "XYZ"): Result Matcher to check if the model contains specified attribute name with specified value XYZ
- view().name("welcome-model-map"): Result Matcher to check if the view name returned is as specified