DbUnit

Darin, the fount of all cool tools I have run across lately, told me about DbUnit. The problem this solves is when the success of your unit tests depend on the state of data in a database – either as a prerequisite for testing or because what you are testing is that the database is in the proper state. That’s what DbUnit does. You set up a testing database (NOT your live one) with the same schema. At the beginning of the unit test, you can have as your setup step the insertion of predefined data. You can also have asserts where you set up some tabular data, and then assert that a table in your database matches that data. If not, your test fails. The guy who wrote it has a story in the documentation about finding out that a “required” field in the database that was only required because marketing guys wanted it was not actually getting inserted. After one year of collecting data, they looked at it and all of it was null, because the resulting data was never examined to see if it was the expected data. I believe I’ll download it tonight and check it out.