I'm using spring 3.2.0 and junit 4
This is my controller method which I need to test
@RequestMapping(value="Home")
public ModelAndView returnHome(){
return new ModelAndView("Home");
}
spring-servlet config is:
<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" />
This is my test class :
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 {
......
......
}
}
How can I test this method with MockMvc ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…