1

我编写了一个单元测试来测试 DAO 的保存方法,我确信我的保存方法有效,但是,当我运行我的单元测试时,它遇到了这个错误:

junit.framework.ComparisonFailure: row count (table=RECONCILIATION_OBJECT_HANDLER) expected:<[4]> but was:<[3]>

这是我的单元测试代码:

@Test
@Transactional
@Rollback(true)
@ExpectedDatabase(value="classpath:/expectedTable/expectedReconciliationHandler.xml",table="RECONCILIATION_OBJECT_HANDLER")
public void testsaveSingleHandler() {
    ReconciliationObjectHandler handler = new ReconciliationObjectHandler();
    handler.setObjectName("employee");
    handler.setHandler("NewHandler");
    dao.saveSingleHandler(handler);
}

这是我的预期结果:

<RECONCILIATION_OBJECT_HANDLER id="0"
                            OBJECT_NAME="employee"
                            HANDLER="FieldNameHandler" />
<RECONCILIATION_OBJECT_HANDLER id="1"
                            OBJECT_NAME="employee"
                            HANDLER="PickListHandler" />
<RECONCILIATION_OBJECT_HANDLER id="2"
                            OBJECT_NAME="employee"
                            HANDLER="SimpleHandler" />
<RECONCILIATION_OBJECT_HANDLER id="3"
                            OBJECT_NAME="employee"
                            HANDLER="NewHandler" />

- - - - - - - - -更新 - - - - - - - - - - - - - - - - -------------

我意识到我不需要添加回滚注释,并且我需要提供所有列信息以进行结果比较,但是,每次我运行单元测试时,INSERT 操作都会使列“id”自动递增,从而产生“id” fireld 将与 xml 文件中的预期结果不匹配,如何忽略比较列“id”?现在错误消息是:

junit.framework.ComparisonFailure: value (table=RECONCILIATION_OBJECT_HANDLER, row=3, col=id) expected:<[3]> but was:<[12]>
4

1 回答 1

0

我通过阅读文档找到了解决方案: Spring Test DBUnit

我可以在注释 @ExpectedDatabase 中选择 assertionMode=DatabaseAssertionMode.NON_STRICT,然后省略我不想要的列。

于 2017-10-11T10:15:44.180 回答