java - 如何使用 Spring dbunit 模拟数据库 View ?

标签 java spring testing integration-testing dbunit

我正在使用 Spring dbunit 编写集成测试。基本上,这很好,但是我需要测试一个查询,但它使用了我的数据库中的一个 View 。我使用 @DatabaseSetup 注释为 xml 提供测试数据集。但是在这个 xml 中,我只能为数据库表配置行,对于 View ,这当然不起作用。有人知道如何在数据库 View 中创建测试行并在测试中使用吗?

非常感谢。

最佳答案

你有几个选择:

1) 您可以创建一个 JPA 实体并使用 View 名称使用 @Table 注释。当然, View 是只读的,因此您将无法保留该实体。

2) 然后用dbunit把数据取到数据库中:

i) Use an H2 in memory database and let hibernate create the database, the view will be created as a table, not a view.

ii) Use a real database and insert the data into the real tables behind the database.

看看这个answer

关于java - 如何使用 Spring dbunit 模拟数据库 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54236323/

相关文章:

java - Spring Messaging 和 GsonMessageConverter 的 LazyInitializationException

java - Spring 启动+ quartz : "Requested bean is currently in creation: Is there an unresolvable circular reference?"

testing - 持久化复杂的测试数据

java - 使用jaxb2-maven-plugin实现不同的接口(interface)

java - 将 WAR 文件部署到 Tomcat 7

java - 使用 CriteriaBuilder 在 Java 中获取列表的 IllegalStateException

Python nose 关键测试与非关键测试

java - 数据报 channel 套接字不编写 Java

java - Spring 中的异常处理程序

testing - nodejs reSTLer 模块测试后调用 EMPTY 主体?