我正在使用 spring 3.2.0 和 junit 4
这是我需要测试的控制器方法
@RequestMapping(value="Home")
public ModelAndView returnHome(){
return new ModelAndView("Home");
}
spring-servlet 配置是:
<context:annotation-config/>
<context:component-scan base-package="com.spring.poc" />
<mvc:annotation-driven />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
这是我的测试课:
public class TestController {
private MockMvc mockMvc;
@Before
public void setup() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/");
viewResolver.setSuffix(".jsp");
this.mockMvc = standaloneSetup(new CController()).setViewResolvers(
viewResolver).build();
}
@Test
public void CControllerTest() throws Exception {
......
......
}
}
如何使用 MockMvc 测试此方法?