Class ServletTestExecutionListener

java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.springframework.test.context.web.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.

Since:
3.2
Author:
Sam Brannen, Phillip Webb