Monday, November 3, 2008

Tests for PublicArt

We have just completed the various tests for PublicArt which completes all of our trackers. We have been thinking what the best way to write the tests are. The recommended way that DBUnit does is to have a sample dataset, run some tests that will change the dataset, then use an "expected" dataset and compare them with the methods DBUnit provides to compare two datasets. The problem with this approach is that for each test we would have to generate an XML file to compare the resulting dataset. This would end up generating literally hundreds if not more xml files that need to be uploaded into the SVN. This may make sense for a large test that represented a complete use case, but not small tests of functionality. The second problem is that it would not really test our model/framework. As per the Hibernate article here http://www.hibernate.org/109.html on Equals and Hashcode, we implemented the methods for eaach model object so that duplicate objects are not generated as well as providing a explicit way for our tests to compare objects. The general manner in which the tests are written are as follows:
  1. Generate a PublicArt Object
  2. Start a Transaction
  3. (optional) Save the PublicArt Object
  4. Commit the transaction
  5. Open a new Transaction
  6. Load a new PublicArt Object from the database
  7. Compare the two objects to each other
  8. End the Transaction
This ensures that the object saved and the object loaded are one and the same in terms of both hashcode() and equals(). We are considering other methods of testing that we may need in order to cover more ground in terms of stressing the framework and testing it's versatility.

No comments: