Unit testing of Data Access Layer code

One of the parts where Unit testing seems to fall apart, or become a giant pain at least, is in applications or parts of applications that rely heavily on data access from a large relational database like sql server.

You run some operations against the database and end up with a result set. Is that result set right? Ok it looks good, now what? Well some people would say that you should restore the DB to the point before you started this last test. This can be very painful if you are trying to run hundreds, or even simply dozens of tests.

In this article on MSDN the author goes over some options for avoiding the use of database restore. There is some talk about using mock objects in conjunction with NMock, which of course Fowler would like to remind you aren’t stubs, but the majority of the article focuses on the use of DTC to rollback changes made in each test teardown.

I had some problems getting DTC to run across machines, but it worked great locally, so there was some success in my tests.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s