Testing

本节总结了 Spring MVC 应用程序中 spring-test 可用的选项。

This section summarizes the options available in spring-test for Spring MVC applications.

  • Servlet API Mock:用于单元测试控制器、过滤器和其他 Web 组件的 Servlet API 契约的模拟实现。有关更多详细信息,请参见 Servlet API 模拟对象。

  • Servlet API Mocks: Mock implementations of Servlet API contracts for unit testing controllers, filters, and other web components. See Servlet API mock objects for more details.

  • TestContext 框架:用于在 JUnit 和 TestNG 测试中加载 Spring 配置,包括在测试方法之间高效缓存加载的配置以及使用 MockServletContext 加载 WebApplicationContext 的支持。有关更多详细信息,请参阅 TestContext Framework

  • TestContext Framework: Support for loading Spring configuration in JUnit and TestNG tests, including efficient caching of the loaded configuration across test methods and support for loading a WebApplicationContext with a MockServletContext. See TestContext Framework for more details.

  • Spring MVC Test:一个框架,也称为 MockMvc,用于通过 DispatcherServlet 测试带注释的控制器(即,支持注释),并使用 Spring MVC 基础结构但没有 HTTP 服务器。有关更多详细信息,请参阅 Spring MVC Test

  • Spring MVC Test: A framework, also known as MockMvc, for testing annotated controllers through the DispatcherServlet (that is, supporting annotations), complete with the Spring MVC infrastructure but without an HTTP server. See Spring MVC Test for more details.

  • 客户端 REST:spring-test 提供一个 MockRestServiceServer,可将其用作模拟服务器,用于测试在内部使用 RestTemplate 的客户端代码。有关更多详细信息,请参阅 Client REST Tests

  • Client-side REST: spring-test provides a MockRestServiceServer that you can use as a mock server for testing client-side code that internally uses the RestTemplate. See Client REST Tests for more details.

  • WebTestClient:专为测试 WebFlux 应用程序而设计,但也可用于端到端集成测试,通过 HTTP 连接连接到任何服务器。它是一个非阻塞、响应式客户端,非常适合测试异步和流传输场景。有关更多详细信息,请参阅 WebTestClient

  • WebTestClient: Built for testing WebFlux applications, but it can also be used for end-to-end integration testing, to any server, over an HTTP connection. It is a non-blocking, reactive client and is well suited for testing asynchronous and streaming scenarios. See WebTestClient for more details.