开发者

Bulk data set up for Unit Test cases

开发者 https://www.devze.com 2023-01-18 04:34 出处:网络
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.

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 everyt开发者_如何学运维ime.

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.


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.


Maybe you could use this framework:

http://jtestcase.sourceforge.net


I am not sure about the Java unit testing frameworks. But in DotNet there is a library called NBuilder which helps you to create test data very easily and quckly. Here is a blog I had written to demonstrate its capabilities.

May be you can try and see if there exists an Java alternative to NBuilder or there is a port of the same available in Java. Most of the DotNet libraries I find are ported from Java world like NHibernate, Spring.Net etc. So my guess is that you might have a Java equivalent of NBuilder as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消