Skip to content

Commit 624c118

Browse files
committed
Polish "Document the pros and cons of MockMvc"
See gh-16718
1 parent 8f8a4af commit 624c118

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5639,11 +5639,15 @@ Alternatively, you can configure a {spring-framework-docs}testing.html#webtestcl
56395639
include::{code-examples}/test/web/MockWebTestClientExampleTests.java[tag=test-mock-web-test-client]
56405640
----
56415641

5642-
Testing within a mocked environment enables fast runs as it does not require the cost of setting up a full Servlet container.
5643-
Although this works fine in most cases, you cannot test situations where the servlet container takes precedence.
5644-
For example, Spring Boot's error handling is based on Servlet container’s error mappings.
5645-
Therefore, exceptions behave differently in the container-less mock environment than the real environment.
5646-
If you need to test the precise format of the error response, test with a fully running server as follows.
5642+
[TIP]
5643+
====
5644+
Testing within a mocked environment is usually faster than running with a full Servlet container.
5645+
However, since mocking occurs at the Spring MVC layer, code that relies on on lower level Servlet concerns cannot be directly tested with MockMvc.
5646+
5647+
For example, Spring Boot's error handling is based on the "`error page`" support provided by the Servlet container.
5648+
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.
5649+
If you need to tests these lower-level concerns, you can start a fully running server as described in the next section.
5650+
====
56475651

56485652

56495653

0 commit comments

Comments
 (0)