tags:

views:

26

answers:

1

When I'm coding in .Net (c#), I use NUnit and Rhino Mock to do testing. Haven't done much database coding (Store Procs). How can we do TDD with database coding (Store Procs)?

A: 

1) Have a framework which allows you to take a DB object, and make a copy of it. This workds well when you have your DB source code including table definitions stored on a filesystem.

  • a copy of a table into a temp database. Including indexes, etc..

  • a copy of stored proc or trigger which replace all the DB names prefixing tables/other called SPs with temp database

  • Able to pre-populate the table with data either cloned from existing table (using some filter) or prepared data set stored, for example, as a bcp input file

2) Have a framework which loads specified test tables with specified test data, then clones all the other needed SP/trigger code

3) Have a framework which executes the cloned stored procs, and evaluates both the results returned from them AND the data left in the table in case they update the data.

Just to give it flavor, it took us a couple of man-months to develop and deploy a full TDD system which included all of the functionality listed here as a small sub-set.


There are also some commertial product available:

http://www.infoq.com/articles/tdd-dbpro-Foy


Also, there are producs for specific DB backends, not sure which one you use:

Postgres: http://en.dklab.ru/lib/dklab_pgunit/


Additional reading:

MSDN http://msdn.microsoft.com/en-us/magazine/cc164243.aspx

http://tddbootcamp.com/2010/01/27/writing-tests-for-stored-procedures/

DVK
Thanks DVK. We are currently using Sybase. I couldn't find any framework for Sybase.
Sheraz Khan
We are on Sybase, so we rolled our own :)
DVK