Limitations when using DbUnit in multi-schema environment

DbUnit has a useful feature when using multiple schemas. After setting a property called http://www.dbunit.org/features/qualifiedTableNames, DbUnit will always refer to a fully qualified table name, using the schema in prefix, as expected.

However, it has the side-effect that the schema is then expected to be stored in the data sets. For example, if using Excel files, you’ll need to rename each sheet. Which is feasible, I guess.

The problem comes when you have multiple developers. You usually do not want them to share a database instance, as running the unit test will frequently reset the data. How do you work around that one?

Another thing is that writing the name of a schema is often overkill, even for test. What I’d really want is default to the user name, as SQL clients often do. Why cannot DbUnit do that?

Update (23/03): DbUnit is supposed to take the default schema name from the JDBC connection. However, that apparently does not work when the schema name is specified in the Hibernate configuration. Since I want to obtain the JDBC connection from the Hibernate connection, I am kind of stuck.

About Eric Lefevre-Ardant

Independent technical consultant.
This entry was posted in java, test. Bookmark the permalink.

1 Response to Limitations when using DbUnit in multi-schema environment

  1. Márcio says:

    Hi Eric,

    1) “The problem comes when you have multiple developers. You usually do not want them to share a database instance, as running the unit test will frequently reset the data. How do you work around that one?”

    if you can, you should have a local database for each developer.

    2) “Another thing is that writing the name of a schema is often overkill, even for test. What I’d really want is default to the user name, as SQL clients often do. Why cannot DbUnit do that?”

    One way that I think was fine for me was writing the name of the schema only in the tests that needed it.

    In my case, this was done by overriding the method from my “TestDatabaseSuperClass” which returns the dbunit connection. See below.

    @Override
    protected IDatabaseConnection getConnection() throws AmbienteTesteException {
    final IDatabaseConnection connection = super.getConnection();
    final DatabaseConfig config = connection.getConfig();

    config.setFeature(“http://www.dbunit.org/features/qualifiedTableNames”, true);

    return connection;
    }

    hope helps.

Comments are closed.