org.dbunit.dataset.NoSuchTableException:加载数据集以进行查看

时间:2015-04-28 10:31:05

标签: dbunit spring-test-dbunit

我期待将dbUnit集成到项目中。该项目有Spring,没有ORM。在将XML数据集加载到db i的时候 org.dbunit.dataset.NoSuchTableException:XXX_VW  " XXX_VW"是一个db视图。但是,我能够将数据集加载到任何表。我在db中确认了所需的视图退出,并且元数据类似。

以下是我在测试的安装方法中执行的代码。

DataSource dc = (MCDataSource) context.getBean("dataSource");
            databaseTester = new DataSourceDatabaseTester(dc, dc.getUsername());
            DatabaseConfig config = databaseTester.getConnection().getConfig();
            config.setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, new String[]{"TABLE", "VIEW"});
            databaseTester.setDataSet(this.getDataSet());
            databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
            databaseTester.onSetup();

知道可能是什么问题吗?

1 个答案:

答案 0 :(得分:0)

而是在OperationListener的生命周期方法中实现和setOperationListener并执行setProperty。

    databaseTester.setOperationListener(new IOperationListener() {

        @Override
        public void operationTearDownFinished(IDatabaseConnection connection) {
            // TODO Auto-generated method stub

        }

        @Override
        public void operationSetUpFinished(IDatabaseConnection connection) {
            // TODO Auto-generated method stub

        }

        @Override
        public void connectionRetrieved(IDatabaseConnection connection) {
            DatabaseConfig config = connection.getConfig();
            config.setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, new String[]{"TABLE", "VIEW"});
    databaseTester.setDataSet(this.getDataSet());
    databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
    databaseTester.onSetup();