spring-projects / spring-projects/spring-framework

Support HTTP status error pages on MockMvc [SPR-13966]

Open
#18,538 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: test in: web type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading MockMvc's error-response handling and the HtmlUnit driver support described in the issue, then compare the requested behavior with Boot's ConfigurableEmbeddedServletContainer#addErrorPages(ErrorPage[]). Determine how configurable HTML error pages should be served for statuses such as 403 and 404, and verify that functional tests can observe the resulting error content.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.