Wednesday, October 29, 2008

More on DBunit

We have only been trying to get dbunit to work as for backing up and restoring the database. This was done using the Maven2 plugin. However, when there is a need for having a sample dataset loaded every single time a test runs (e.g. during setUp() for JUnit) it isn't practical. This is because a Maven2 plugin can only be attached to a certain phase of the Maven2 build lifecycle, meaning the sample dataset would only load once at the beginning of all tests. So in order to have the sample dataset load for each test, we added the dbunit 2.3.0 as a dependency in Maven2 and use its original implementation. It has it's own DBTestCase class instead of the JUnit testcase, which is, we believe, just a subclass of the JUnit TestCase class anyway. It can also be used in a regular JUnit TestCase class as well, the initialization of some DBUnit specific variables just have to be done manually. This changes what we have been previously done for tests, which is simply programmatically inserting values through Hibernate, then running tests on the few tests we did. Now, we have 150 rows of sample data from the Public Art application as our test data. There are still some issues, but should be resolved summarily as we understand more about DBUnit.

No comments: