JDBC 測試支援

JdbcTestUtils

org.springframework.test.jdbc 包中包含 JdbcTestUtils,這是一組 JDBC 相關的實用函式,旨在簡化標準的資料庫測試場景。具體來說,JdbcTestUtils 提供了以下靜態實用方法。

  • countRowsInTable(..): 計算給定表中的行數。

  • countRowsInTableWhere(..): 使用提供的 WHERE 子句計算給定表中的行數。

  • deleteFromTables(..): 刪除指定表中的所有行。

  • deleteFromTableWhere(..): 使用提供的 WHERE 子句從給定表中刪除行。

  • dropTables(..): 刪除指定的表。

AbstractTransactionalJUnit4SpringContextTestsAbstractTransactionalTestNGSpringContextTests 提供了方便的方法,它們委託給 JdbcTestUtils 中上述方法。

嵌入式資料庫

spring-jdbc 模組提供了配置和啟動嵌入式資料庫的支援,您可以在與資料庫互動的整合測試中使用它。有關詳細資訊,請參閱嵌入式資料庫支援使用嵌入式資料庫測試資料訪問邏輯

© . This site is unofficial and not affiliated with VMware.