DBUnit Sybase unable to CLEAN_INSERT

馋奶兔 提交于 2019-12-06 15:14:19

I have come to the conclusion that this is indeed a problem with Sybase + DBUnit after hitting the same issues on another project (although I am using the same JAR file versions and database server).

The workaround I finally settled on was the following

@Before 
public void setUp() throws Exception {
    InsertIdentityOperation.TRUNCATE_TABLE.execute(getConnection(), getDataSet());
    InsertIdentityOperation.INSERT.execute(getConnection(), getDataSet());
}

The caveat is that the TRUNCATE will obviously blow away all data in the database tables when the test runs, but this is something I can live with. At least I know for certain what data is in the database and my tests are less likely to fail due to erroneous records being inserted by other developers running in between test executions. Probably a good reason why you want a dedicated database for unit + integration tests.

nitin

Simply use INSERT Operation for inserting Values through XML or DataSet. The XML or inserting script should insert the data in order i.e parent first and then child, use DELETE_ALL Operation for Deleting the Tables in reverse order.

protected DatabaseOperation getSetUpOperation() throws Exception
    {
        return DatabaseOperation.INSERT;

    }

    protected DatabaseOperation getTearDownOperation() throws Exception
    {  
        return DatabaseOperation.DELETE_ALL;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!