我正在使用 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/