HtmlUnit Integration

Spring 提供了MockMvcHtmlUnit之间的集成。这简化了在使用基于 HTML 的视图时执行端到端测试。此集成允许您:

Spring provides integration between MockMvc and HtmlUnit. This simplifies performing end-to-end testing when using HTML-based views. This integration lets you:

  • 使用诸如 HtmlUnitWebDriverGeb之类的工具轻松测试 HTML 页面,无需部署到 Servlet 容器。

  • Easily test HTML pages by using tools such as HtmlUnit, WebDriver, and Geb without the need to deploy to a Servlet container.

  • Test JavaScript within pages.

  • 还可选择使用模拟服务来进行测试,以加快测试速度。

  • Optionally, test using mock services to speed up testing.

  • 在容器内的端到端测试与容器外的集成测试之间共享逻辑。

  • Share logic between in-container end-to-end tests and out-of-container integration tests.

MockMvc 使用不依赖于 Servlet 容器的模板技术(例如,Thymeleaf、FreeMarker 等),但它不适用于 JSP,因为后者依赖于 Servlet 容器。

MockMvc works with templating technologies that do not rely on a Servlet Container (for example, Thymeleaf, FreeMarker, and others), but it does not work with JSPs, since they rely on the Servlet container.