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:
- Associating each *DaoTest with a separate unitils.properties file that would hold configuration for this DAO's database. Is it even possible?
- 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.propertiesfor each DAO which defines every datasource my project needs to test. In theunittils.propertiesfile, I defined adatabase.schemaNames=DATABASE_1, DATABASE_2property.Then, you can modify your dataset definition to look something like this:
Note that
some_tablewill be assumed to live inDATABASE_1. This is because unittils sets the first database in thedatabase.schemaNamesproperty as the default. You can optionally omit thexmlns="DATABASE_1"in your dataset's xml file because of this.