3.3. JDBC 测试支持 {#integration-testing-support-jdbc

    预计阅读时间: 2 分钟

    The org.springframework.test.jdbc package contains JdbcTestUtils, which is a collection of JDBC-related utility functions intended to simplify standard database testing scenarios. Specifically, JdbcTestUtils provides the following static utility methods.
    The org.springframework.test.jdbc package contains JdbcTestUtils , which is a collection of JDBC-related utility functions intended to simplify standard database testing scenarios. Specifically, JdbcTestUtils provides the following static utility methods. 该 org.springframework.test.jdbc 包含 JdbcTestUtils ,它是一组旨在简化标准数据库测试场景的 JDBC 相关实用函数。具体来说,JdbcTestUtils 提供以下静态实用方法。

    • countRowsInTable(..): Counts the number of rows in the given table.
      countRowsInTable(..) :计算给定表中行数。

    • countRowsInTableWhere(..): Counts the number of rows in the given table by using the provided WHERE clause.
      countRowsInTableWhere(..) :通过提供的 WHERE 子句计算给定表中行数。

    • deleteFromTables(..): Deletes all rows from the specified tables.
      deleteFromTables(..) : 从指定的表中删除所有行。

    • deleteFromTableWhere(..): Deletes rows from the given table by using the provided WHERE clause.
      deleteFromTableWhere(..) :通过提供的 WHERE 子句从给定表中删除行。

    • dropTables(..): Drops the specified tables.
      dropTables(..) : 删除指定的表。

    AbstractTransactionalJUnit4SpringContextTests and AbstractTransactionalTestNGSpringContextTests provide convenience methods that delegate to the aforementioned methods in JdbcTestUtils.
    AbstractTransactionalJUnit4SpringContextTestsAbstractTransactionalTestNGSpringContextTests 提供了委托给 JdbcTestUtils 中所述方法的便捷方法。

    The spring-jdbc module provides support for configuring and launching an embedded database, which you can use in integration tests that interact with a database. For details, see Embedded Database Support and Testing Data Access Logic with an Embedded Database.
    spring-jdbc 模块提供配置和启动嵌入式数据库的支持,您可以在与数据库交互的集成测试中使用它。有关详细信息,请参阅嵌入式数据库支持和使用嵌入式数据库测试数据访问逻辑。