Spring 测试 webEnvironment=RANDOM_PORT 对比 webEnvironment=MOCK

Spring test webEnvironment=RANDOM_PORT vs webEnvironment=MOCK

我知道在 spring 测试中使用 webEnvironment=RANDOM_PORT 时,spring 将 运行 Web 服务器,测试将涵盖从真实 http 请求开始的场景,同时webEnvironment=MOCK 只会模拟网络服务器的行为。

我已经看过 Difference between webEnvironment = RANDOM_PORT and webEnvironment = MOCK

由于similar question中没有回答,目前尚不清楚使用RANDOM_PORT会捕获到哪些失败场景,MOCK无法捕获。

先谢谢了。

我在 docs

中找到了一个示例

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 custom error page is rendered. If you need to test these lower-level concerns, you can start a fully running server as described in the next section.