Fog Creek Software
Discussion Board

Unit Testing and Databases

I know this is a perenial question but I figured it was about time to ask it again.  How do you do Unit Tests with Database functionality effectively?

I have mainly been working away from databases so I haven't had to deal with the problem before.  My existing tests really save a lot of time and problems so I would like to adapt to doing the same for code that manipulates data in databases.

How do you maintain the 'before' data and how do you check the results best?

Colin Newell
Wednesday, February 11, 2004

Abominable Power
Wednesday, February 11, 2004

I created an in-house system where the data representing different scenarios is represented in XML files (of course...) and a process runs through them to create a load script for an in-memory database. (HSQLDB in my case.) The in-memory database can be loaded very quickly -- DDL for a few hundred tables and thousands of records in a few seconds -- which makes it very useful for unit testing. Representing the data for the different scenarios externally makes it easier for domain knowledge people to do what they need to do.

The processes using those objects don't care how they're filled with data nor how they're saved and go along their merry way doing their job, which I've hopefully broken down sufficiently to test befores and afters.

Chris Winters
Thursday, February 12, 2004

*  Recent Topics

*  Fog Creek Home