上QQ阅读APP看书,第一时间看更新
Setting up the Controller to test
This step is very similar to the previous flow. We want to test BasicViewController. We instantiate MockMvc using BasicViewController. We also configure a simple view resolver:
public class BasicViewControllerTest {
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup
(new BasicViewController())
.setViewResolvers(viewResolver()).build();
}
private ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver =
new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}