In a previous post I looked at Unitils. This is a quick update.
Conclusion
Yes its great but the product could do with some polish, better documentation, bug fixing and some api revision. Despite that its still the best system I have looked at to test a DAO. Also the project is alive and kicking, it looks like there is more to come in future revisions.
Technical Detail
- Unitils provides two handy annotations, @DataSet and @ExpectedDataset. DataSet is used to specify xml describing tables, colums and data to be setup before the test. The workflow for basic testing is a joy, and very test driven:
- Setup empty test method with annotation for file or files describing the data.
- Add files and extend data until you no longer have foreign key insert failures. Enrich data until your happy.
- Add dao search call.
- Add assertions and simple expectations.
- Tidy test code.
- @ExpectedDataset makes insert, update and delete tests very simple. Once you have your dataset, you just copy the file, add, delete or amend a record, watch the test fail, then add the dao calls to fix it. Nb. see below, delete is not working in 2.1.
- Very good test failure reporting with lists of differences.
- assertReflectionPropertyEquals is not helpful in my demo model because I can’t get at the identifiers, so you get null or 0 match failures. I could not get IGNORE_DEFAULTS to work. Not too much of an issue as its possible to hand assert by building standard validation routines and these are little effort. There is an incarnation that has this signature:
assertPropertyReflectionEquals(java.lang.String propertyName, java.util.Collection expectedPropertyValues, java.util.Collection actualObjects, ReflectionComparatorMode... modes)
That one I liked a lot, as I could check a single property across a collection, with a range of values. Nice!
The next one I am not so keen on.
assertPropertyLenientEquals("id", 1, user);
I would rather use this, as I find it more descriptive, and type safe.
assertEquals(1L, user.getId);
In the main though I would use it should the need arise.













I have been talking with Tim Ducheyne about requirements and bug fixes. This is how to solve the parent record issue, just add null for the parent id.
parent_id=”[null]“