3.1. 概述

    预计阅读时间: 3 分钟

    It is important to be able to perform some integration testing without requiring deployment to your application server or connecting to other enterprise infrastructure. Doing so lets you test things such as:
    执行一些集成测试而不需要部署到您的应用程序服务器或连接到其他企业基础设施是很重要的。这样做可以测试以下内容:

    • The correct wiring of your Spring IoC container contexts.
      正确配置您的 Spring IoC 容器上下文。

    • Data access using JDBC or an ORM tool. This can include such things as the correctness of SQL statements, Hibernate queries, JPA entity mappings, and so forth.
      使用 JDBC 或 ORM 工具进行数据访问。这可能包括诸如 SQL 语句的正确性、Hibernate 查询、JPA 实体映射等内容。

    The Spring Framework provides first-class support for integration testing in the spring-test module. The name of the actual JAR file might include the release version and might also be in the long org.springframework.test form, depending on where you get it from (see the section on Dependency Management for an explanation). This library includes the org.springframework.test package, which contains valuable classes for integration testing with a Spring container. This testing does not rely on an application server or other deployment environment.
    Spring 框架在 spring-test 模块中提供了对集成测试的一级支持。实际的 JAR 文件名可能包含发布版本,也可能采用长 org.springframework.test 形式,具体取决于获取方式(参见依赖管理部分以获取解释)。该库包括 org.springframework.test 包,其中包含与 Spring 容器进行集成测试的有价值类。这种测试不依赖于应用服务器或其他部署环境。
    Such tests are slower to run than unit tests but much faster than the equivalent Selenium tests or remote tests that rely on deployment to an application server.
    此类测试的运行速度比单元测试慢,但比等效的 Selenium 测试或依赖于部署到应用服务器的远程测试要快得多。

    Unit and integration testing support is provided in the form of the annotation-driven Spring TestContext Framework. The TestContext framework is agnostic of the actual testing framework in use, which allows instrumentation of tests in various environments, including JUnit, TestNG, and others.
    单元和集成测试支持以注解驱动的 Spring TestContext 框架的形式提供。TestContext 框架对实际使用的测试框架无关,这允许在各种环境中对测试进行仪器化,包括 JUnit、TestNG 以及其他。