dcsimg
JUnit - Testcase for a class operating on data from db.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ramprakash_rajamanickam
Posted On:   Tuesday, July 8, 2003 06:18 AM

I have a class which picks up data from a database and formats the data so that the data is suitable for display. I want to unit test this class. Basically i want to test if the formatting is done properly. Since the data returned is dependant on the data in the database, a test case i write today would be made invalid by new data in database.


One approach i am aware is to solve this problem is
to populate test data in database in setUp() and rolling back in the tearDown() method (basically operate on data the testcase puts in.


Is there any better way of handling this scenario ?

Re: JUnit - Testcase for a class operating on data from db.

Posted By:   Anonymous  
Posted On:   Wednesday, July 9, 2003 12:51 AM

Yes - decouple the formatting from acces to the database. Write your formatting class in a way that it doesn't care about where the data is coming from. This way you not only get a more testable class, but also a more reusable one.
About | Sitemap | Contact