468,771 Members | 1,935 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Test-Driven Development with Databases, what is the best way to doit?

Hi everybody,

I am starting a new ASP.NET/SQL Server project and this time I want to
do it through Test-Driven Development (TDD). The problem that I ran into
is this: How do you test data access logic with a database in the
backend? I do not want to use mock objects because if the schema changes
I will miss those errors.

If you are using TDD to test data access code, please post the
description of your setup or some pointers and suggestions.

Thank you very much for your help!

Sasha
Nov 19 '05 #1
3 1445
look at mbunit

-- bruce (sqlwork.com)

"Sasha" <no*****@noemail.com> wrote in message
news:O2**************@TK2MSFTNGP15.phx.gbl...
| Hi everybody,
|
| I am starting a new ASP.NET/SQL Server project and this time I want to
| do it through Test-Driven Development (TDD). The problem that I ran into
| is this: How do you test data access logic with a database in the
| backend? I do not want to use mock objects because if the schema changes
| I will miss those errors.
|
| If you are using TDD to test data access code, please post the
| description of your setup or some pointers and suggestions.
|
| Thank you very much for your help!
|
| Sasha
Nov 19 '05 #2
Without Mock objects, testing the DAL is challenging. One way I would do it
is:

1. Unit test your database code separately -- using something like
T-SQLUnit.
2. Create a "baseline" database to test your DAL objects
3. Write unit-tests for your DAL objects. Make sure that after each test,
the database returns to the original state -- using TearDown.

The most challenging parts I found were if you were using identity columns,
and want to unit test object IDs.

Hope that helps, but if you find a better answer please post it to the
newsgroup.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Sasha" <no*****@noemail.com> wrote in message
news:O2**************@TK2MSFTNGP15.phx.gbl...
Hi everybody,

I am starting a new ASP.NET/SQL Server project and this time I want to
do it through Test-Driven Development (TDD). The problem that I ran into
is this: How do you test data access logic with a database in the
backend? I do not want to use mock objects because if the schema changes
I will miss those errors.

If you are using TDD to test data access code, please post the
description of your setup or some pointers and suggestions.

Thank you very much for your help!

Sasha

Nov 19 '05 #3
Hi Sasha:

Two thoughts to consider:

Depending on your design you could use an O/R mapper or code
generation tool to spit out code. There are advantages and
disadvantages to this approach, of course, but one of the advantages
is you'll have compile errors if the upper layer code is not keeping
up with the schema changes.

Unit testing code that needs access to the database can be tricky,
using mock objects doesn't solve all the problems of course but it can
remove some dependencies and make testing easier. One approach I've
seen used is to test against the real db, but wrap your test methods
with enterprise transactions, there is a discussion here:
http://weblogs.asp.net/rosherove/art...ittesting.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Wed, 02 Mar 2005 11:29:04 -0800, Sasha <no*****@noemail.com> wrote:
Hi everybody,

I am starting a new ASP.NET/SQL Server project and this time I want to
do it through Test-Driven Development (TDD). The problem that I ran into
is this: How do you test data access logic with a database in the
backend? I do not want to use mock objects because if the schema changes
I will miss those errors.

If you are using TDD to test data access code, please post the
description of your setup or some pointers and suggestions.

Thank you very much for your help!

Sasha


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Berthold Hoellmann | last post: by
reply views Thread by Remy Blank | last post: by
4 posts views Thread by Edvard Majakari | last post: by
41 posts views Thread by Roy Smith | last post: by
reply views Thread by Jussi Mononen | last post: by
6 posts views Thread by ypjofficial | last post: by
2 posts views Thread by Netkiller | last post: by
176 posts views Thread by nw | last post: by
7 posts views Thread by laura | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.