DBunit 找不到数据集上定义的表
我有一个数据集(在 xml 中定义),我正在使用 PostGreSQL、用 JPA 注释的 POJO 以及带有 Junit 的 DbUnit 进行测试。
测试运行时,它会在数据库中创建表和序列,但是当它开始读取包含表定义和列的数据集 (xml) 时,会引发以下错误 org.dbunit.dataset.NoSuchTableException "nameoftable" 我尝试将表的名称全部大写和普通大写,但它不起作用。该表是在公共模式中创建的,然后我尝试在 xml 中将表定义为 public."nameoftable" 但它也不起作用......有什么想法吗?
我尝试使用以下版本的 DUnit 运行此测试:2.2.2、2.3.0 和 2.4.5。
谢谢。
I have a dataset (defined in xml) and i am using PostGreSQL, POJOs annotated with JPA, and DbUnit with Junit for tests.
When the test runs, it creates the tables and sequences in the database, but when it starts to read the dataset (xml) with the table definitions and columns, it fires the following error
org.dbunit.dataset.NoSuchTableException "nameoftable" I tried to put the name of the table with all caps and normal caps, and it won't work. The table was created in the public schema, and then i tried to define in the xml the table as public."nameoftable" but it also won't work.... any ideas?
I tried to run this tests with DUnit in the following versions: 2.2.2, 2.3.0, and 2.4.5.
Thanks.
使用 DBUnit,您可以使用特定模式进行测试,也可以使用完整数据库(可能具有多个模式)。如果您使用后者,则需要在导入/导出时指定数据集中的架构,否则它可能会造成混淆;至少在 PostgreSQL 中,我没有尝试过其他任何东西。
要强制执行此操作,请添加以下代码:
重要的是属性的设置;其余部分是我用来建立与数据库或架构相关的连接的东西(基于从 hibernate 配置 XML 中提取的架构名称)。
With DBUnit you can either use a specific schema to test against, or a full database (with potentially multiple schema). If you use the latter you need to specify the schema in the dataset when importing/exporting or it can get itself confused; in PostgreSQL at least, I've not tried it with anything else.
To enforce this add the following code in:
The important bit is the setting of the property; the rest is something I use to make the connection relevant to the DB or schema (based upon a schema name extracted from the hibernate config XML).