views:

36

answers:

2

I have developed an application with Spring MVC that deals with bulk data insert/update. For ex: There are some use cases that insert a record with 100-125 attributes.

For bulk data insert, I'm hard coding the values to be inserted in my Unit test class. I have Transfer Object to carry the data, so i'm populating these TOs in my Unit test cases and then calling the desired operation to be tested. For every DAO, at least 4 test cases are needed for unit testing CRUD operations.

I'm finding it very hard to populate the TOs by hard coding the values in my test case source file. Imaging writing 125 setters for every unit test case. I want to populate my TOs dynamically by reading the data from an XML file or any kind of media, so that I need not change the hard coded data for test cases everytime.

Setting up the data in an XML file is much easier than hard coding the values in JUNIT source files.

I could think of some innovative solutions like setting up data in XML file and then using any JAXB implementation to read the same and populate the TOs.. but i believe there much be some easy and better way to handle this kind of requirement.

Need some help on this.

A: 

Maybe you could use this framework:

http://jtestcase.sourceforge.net

slamidtfyn
A: 

Imaging writing 125 setters for every unit test case.

You need test helper method(s) that take care of test data. Then you call appropriate method that populates a TO: it could be as little as 0 parameters (completely random/fixed, not test driven) or as many as 125 (completely controlled by the test) (and anything in between).

Either way no setters in tests anymore.

grigory