Class ServletTestExecutionListener

All Implemented Interfaces:
Ordered, TestExecutionListener

public class ServletTestExecutionListener extends AbstractTestExecutionListener
TestExecutionListener which provides mock Servlet API support to WebApplicationContexts loaded by the Spring TestContext Framework.

Specifically, ServletTestExecutionListener sets up thread-local state via Spring Web's RequestContextHolder during test instance preparation and before each test method and creates a MockHttpServletRequest, MockHttpServletResponse, and ServletWebRequest based on the MockServletContext present in the WebApplicationContext. This listener also ensures that the MockHttpServletResponse and ServletWebRequest can be injected into the test instance, and once the test is complete this listener cleans up thread-local state.

Note that ServletTestExecutionListener is enabled by default but generally takes no action if the test class is not annotated with @WebAppConfiguration. See the javadocs for individual methods in this class for details.

Sam Brannen, Phillip Webb