Christopher Smith opened SPR-13966 and commented
MockMvc does not run an actual servlet container but implements part of the stack for testing purposes. Currently, MockMvc does not support content in error responses; for example, a 403 or 404 status will result in an empty body.
With the new HtmlUnit driver support, it's very simple to write most functional tests in something like Spock+Geb, but tests that expect an error (e.g., "Bob can't view Alice's document") require dropping back into the MockMvc DSL because the driver only exposes the view content and not the status code.
I would like to be able to configure the MockMvc to serve HTML pages as error responses, similar to Boot's ConfigurableEmbeddedServletContainer#addErrorPages(ErrorPage[])
so that I can use ordinary Selenium methods of identifying when I've encountered an error.
Affects: 4.2.4
Comment From: spring-projects-issues
Rossen Stoyanchev commented
So is this a limitation of the HtmlUnit driver or our support for it? In other words could we expose the status code?
Comment From: spring-projects-issues
Rob Winch commented
I think Christopher Smith is asking for MockMvc to be able to process HttpServletResponse.sendError
. Since it is unable to, that means the error handling that leverages HttpServletResponse.sendError
cannot be tested with the HtmlUnit support.