{ by david linsin }

April 09, 2007

Unitilis

Unitilis is a nice library which supports unit testing with Spring and Hibernate. The article above gives a short overview of the capabilities of Unitilis like integration with Spring, provisioning of test data and asserting results.

I think the library is nice, but actually I don't see any imperative for it! Spring offers a wide range of testing capabilities, which I think work fairly well! So the question I'm asking myself is why bring in another library? I can use Spring to test almost everything, all I have to do is extends a Spring-test-class and I'm good to go.

As for the provisioning of test data, Unitilis uses an XML file to define a set of test data which is being loaded before the unit test method is executed. One of my approaches is using the setUp() method to programatically fill POJOs with test data. Although a little tedious, the compiler would tell me immediately if something went wrong, for instance during refactoring my domain model. I believe the XML approach is suboptimal in this case.

Unitilis provides a so called "reflection assert utility" that compares all fields of an expected and actual object. This is a really nice feature and I hope you can use this without any of the other Unitilis stuff. My approach so far is asserting every field "by hand". Unititlies takes care of that for you and in addition you can specify whether it should be lenient or not, when it comes across null/0 values. Check out this example take from the article above:

ReflectionAssert.assertRefEquals(new Person("John", "Doe"), result.get(0));

It checks every field of the object in the list of results, if it matches the field of the expected object. In my opinion this is a great feature and I'm definitely gonna incorporate this into my unit tests at work.

To wrap this up, I really don't see any imperative for this library at least if you are using Spring heavily. I might be wrong and if so please drop me a line! I really like the assert feature using reflection and I think I'm gonna start using that from now on.

0 comments:


com_channels

  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)

recent_postings

loading...