Otaku, Cedric's weblog lists a few woes of DbUnit. Here are few answers to C馘ric's post.
We've been using DbUnit for a year now with our automated tests and we have no problems with getting connections and we have literaly hundreds of tests running every hour.
You don't have to have your test data in a separate XML file. The xml is just used to describe a single line in the DB. If you look at how you inject data into the DB, you don't have to do it through a file like the docs recommended (at least the old ones), you can do it from a String.
In our test suite, we have an XML file for every table which we use in 99% of the tests. It's really just an extract from the original test database.
For very special test cases, we inject a string contained in the test code instead of the whole XML "table".
We have found this method to be invaluable just to be able to handle references and constraints.
You could also go overboard and have a single XML file define the whole database but we decided against that for maintenance purposes.
About C馘ric's properties file comment : I agree but it's more "wordy" and breaks the natural inclination people will have in reading a single XML line as a single database row.
I haven't tested version 2 yet but there was a problem similar to the one described in C馘ric's second post in version 1.5.x. Omiting a "column" in the XML definition resulted in the column getting NULLed. Omitting the column on the first row getting inserted resulted in all rows getting that column NULLed even if the other rows had the column valued.
Why would you write your own framework on top of JUnit rather than DbUnit... Why would you ? I like all of DbUnit except the NULLing column bug, really don't see anything wrong with it.
An article about DbUnit and how we have used it is in the final review process at developerworks...
Good response...
I was just wondering what database you guys are using. We are trying to adopt DBUnit but are having a hard time managing referential integrity when reloading the database with the test data (mostly when deleting old test data).
Could you share a pointer as to how you accomplish that?
Posted by: Mikkel Heisterberg at January 26, 2004 03:55 PMWe are doing this on multiple oracle schemas.
As for referential integrity there are two ways
i) drop all constraints on the test databases. This is yucky but makes life easier
ii) keep track of the order in which your tables must be loaded. You then know the order in which they must be removed. Although we don't do it this way, this is definatly the way I want to do it the next time I do setup automated tests. My current idea is to keep track of table dependencies and compute all necessary tables for seting up any table. Am I making any sense to you ?
I don't think option 1 will be usable in practice since you wouldn't be able to detect errors that occur from bad data being inserted.
I have also thought along the lines of your second suggestion but when you have a fair number of tables it becomes almost impossible to figure the right sequence out. It can of cause be that there is not easy way and since is simply the price to pay for leveraging dbunit in your setup.
One think I have been wondering - do you guys use one "master" dataset for testing or do you have multiple smaller ones for specific tests ? I thought of splitting my datasets into more manageble chunks but discarded the approach since it would be unmanagable to run the tests from the build file. Any thoughts ?
lekkim
Posted by: Mikkel Heisterberg at February 4, 2004 08:54 PMI don't think so
Posted by: Mer at February 6, 2004 10:59 AMMikael,
Do you think there cannot be a quick algorithm to figure out the correct sequence in which tables can be inserted if their dependencies are tracked ? I haven't given it any thought but really cannot find any reason why not, that's "just" graph theory isn't it ?
As for our test data, yes, we have a set of files that describes a coherant database. But we do have some test-specific files that we sometimes use. Or we just insert plain Strings that describe the XML for the table in some other tests... it's just a matter of how many lines there are.
I must confess that we have dropped all constraints on the test DB though which makes this easier :(
Here are some strategies I use to circumvent aforementioned issues.
1. Computing insert sequence automatically
There is a new class in DbUnit 2.0, DatabaseSequenceFilter, which does that. I知 using it to export my DTD and make sure that all my datasets conform to it when editing them. Using it once prevent adding overheads when executing my tests.
http://www.dbunit.org/faq.html#tableseq
2. Deleting old data
I知 using a strategy similar to CLEAN_INSERT but in two steps and with two different datasets. Note that I知 not extending the DatabaseTestCase class but implemented my own. First, I知 doing a DELETE_ALL with the above DTD as dataset to clean the whole database. I知 filtering out configuration, read-only and rarely used tables from the DTD. Second, I perform an INSERT with my test class dataset.
3. One large dataset vs multiple small datasets
I知 personally using multiple small datasets. One dataset per test class, having the same name and automatically loaded by my base class. Datasets are relatively easy to manage because there is a one to one relationship between datasets and test classes. This way I知 very confident to not break other test classes when I add or modify my test class dataset. This also allows more developers to work in parallel without conflict since not editing the same global dataset.
I kind of already discussed these strategies before in the dbunit-user mailing list:
http://sourceforge.net/mailarchive/message.php?msg_id=7063085
I知 currently setting up a DbUnit Wiki. My intention is to allow people to capture, organize and discuss such patterns, best practices and recurrent issues about DbUnit and DatabaseTesting in general. I believe that this Wiki will be a more appropriate medium than the existing mailing list.
http://www.dbunit.org/wiki/
Hoping to read you there!
Googl
Posted by: Googl at May 27, 2004 09:00 PMOk, I will sign your blog. I really love your site.
Online Casino Gambling Guide with Cross-media Online Casinos
Posted by: Online Casino Gambling Guide with Cross-media Online Casinos at May 31, 2004 09:57 PMhi, just popped in here through a random link. cool site, keep this good work up :-)
best online casinos
Posted by: best online casinos at July 25, 2004 04:48 PMenjoyed reading your posts.
best online casinos
Posted by: best online casinos at July 25, 2004 10:37 PMgreat site and great information.
online casinos
Posted by: online casinos at July 27, 2004 06:44 AMcongrats mate! fine job and fine site!
online casinos
Posted by: online casinos at July 27, 2004 01:22 PMIs it worth using DbUnit in a reporting project.
In reporting project you generally read selective data from various tables and display it to the user. So does it make sense to use DbUnit here ?
Thanks for great info
Posted by: Buy viagra online info at July 29, 2004 03:57 PMThanks for good info!
Posted by: Wedding dresses, medievil info at August 3, 2004 11:34 PMvery useful comments - good to read
business grants
Posted by: business grants at August 7, 2004 10:35 AMThanks for your useful information!
Posted by: Health insurance info at August 16, 2004 02:55 PMI agree with you :) Thanks!
Posted by: 3 day diet center at August 19, 2004 11:32 AM