Testing Spring MVC

This section will mock the request and session scope beans with MockHttpServletRequest and MockHttpSession:

  1. Create a dynamic web project, SpringWebTest, add the Spring-mvc jars to the classpath, and modify the web.xml file (stored under <project>/WebContent/WEB-INF/) to enable Spring DispatcherServlet as follows:
    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>SpringWebTest</display-name> <servlet> <servlet-name>dispatcher</servlet-name> ...

Get Mockito for Spring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.