DBUnit导致SQL错误时,我遇到了这个问题。假设我把这个放在我的dbunit testdata.xml文件中:
<myschema.mytable id="1" value1="blah" value2="foo" />
我有一张这样的桌子(postgres)
myschema.mytable有一个id、value1、value2和一个日期字段,比如“lastmodified”。最后修改的列是带有修饰符“null now()”的时间戳。
看起来,dbunit读取表元数据,并试图为我的testdata.xml文件中未指定的任何列插入空。因此,上面的xml结果是这样的插入:
insert into myschema.mytable (id,value1,value2,lastmodified) values (1,'blah','foo',null)
在运行测试(dbunit/maven插件)时,我会得到如下错误:
Error executing database operation: REFRESH: org.postgresql.util.PSQLException: ERROR: null value in column "lastmodified" violates not-null constraint
有什么方法可以告诉DBUnit不要在我没有指定的字段中插入空值?
编辑:使用dbunit 2.5.3,junit 4.12,postgressql驱动程序9.4.1208
发布于 2018-06-17 00:11:00
使用dbUnit“排除列”特性:如何在运行时排除某些表列?
在FilteredTableMetaData 2.1中引入的DbUnit类可以与IColumnFilter接口结合使用,以决定在运行时包含或排除表列。 新FilteredTableMetaData(originalTable.getTableMetaData(),FilteredTableMetaData MyColumnFilter();ITable filteredTable =新CompositeTable( metaData,originalTable);
https://stackoverflow.com/questions/50878231
复制相似问题