Using Betwixt to Aid in Unit Testing
One problem I'm facing at work is the labor-intensive process of composing complex data structures for use in unit testing. Sure, I can consolidate a lot of the object contruction in the JUnit setup method; however, it still amounts to a lot of code and remains hard to visualize the overall object structure. So, I need a better way to compose my test data structures.
Enter Betwixt, a tool I'm looking to use in another problem domain for Java object (de)serialization. In this case, I can represent my test data structure content as an XML document and use Betwixt to populate the structures. Similarly, the end-result test data structures can be deserialized to XML and validated using a simple String comparison. If the structure changes or I want to alter the test data, I simply need to edit the XML document. This is easier to conceptualize and maintain. I now realize that the approach is very similar to how the dbunit tool uses XML document instances to set up databases before and after running unit tests.