简体   繁体   中英

Unitils/DbUnit: How to test in a multi-database environment?

I'm using Unitils (with DbUnit) for my data access layer unit testing, but the need has arisen to test multiple databases. What's the best way to do it? The databases are different so some DAOs are for one database, another DAOs are for another.

I see the following alternatives:

  1. Associating each *DaoTest with a separate unitils.properties file that would hold configuration for this DAO's database. Is it even possible?
  2. Having a separate test project for every database (holding this database's *DaoTests and a unitils.properties file with the database's credentials)

Any other ideas?

Hopefully you found an answer for this in the 6 years since you originally asked :)

I recently found myself with this same issue and resolved it this way:

I used a single unittils.properties for each DAO which defines every datasource my project needs to test. In the unittils.properties file, I defined a database.schemaNames=DATABASE_1, DATABASE_2 property.

Then, you can modify your dataset definition to look something like this:

<?xml version='1.0' encoding='UTF-8'?>
<dataset xmlns="DATABASE_1" xmlns:b="DATABASE_2">
    <some_table />
    <b:some_other_table />

    <some_table attr_1="foo" attr_2="bar" />
    <b:some_other_table other_attr="baz" />
</dataset>

Note that some_table will be assumed to live in DATABASE_1 . This is because unittils sets the first database in the database.schemaNames property as the default. You can optionally omit the xmlns="DATABASE_1" in your dataset's xml file because of this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM