Commit 624c118c authored by Phillip Webb's avatar Phillip Webb

Polish "Document the pros and cons of MockMvc"

See gh-16718
parent 8f8a4af0
...@@ -5639,11 +5639,15 @@ Alternatively, you can configure a {spring-framework-docs}testing.html#webtestcl ...@@ -5639,11 +5639,15 @@ Alternatively, you can configure a {spring-framework-docs}testing.html#webtestcl
include::{code-examples}/test/web/MockWebTestClientExampleTests.java[tag=test-mock-web-test-client] include::{code-examples}/test/web/MockWebTestClientExampleTests.java[tag=test-mock-web-test-client]
---- ----
Testing within a mocked environment enables fast runs as it does not require the cost of setting up a full Servlet container. [TIP]
Although this works fine in most cases, you cannot test situations where the servlet container takes precedence. ====
For example, Spring Boot's error handling is based on Servlet container’s error mappings. Testing within a mocked environment is usually faster than running with a full Servlet container.
Therefore, exceptions behave differently in the container-less mock environment than the real environment. However, since mocking occurs at the Spring MVC layer, code that relies on on lower level Servlet concerns cannot be directly tested with MockMvc.
If you need to test the precise format of the error response, test with a fully running server as follows.
For example, Spring Boot's error handling is based on the "`error page`" support provided by the Servlet container.
This means that, whilst you can test your MVC layer throws and handles exceptions as expected, you cannot directly test that a specific <<#boot-features-error-handling-custom-error-pages, custom error page>> is rendered.
If you need to tests these lower-level concerns, you can start a fully running server as described in the next section.
====
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment