Re: Best Way to Test Against a Database
- From: Joachim Van den Bogaert <joachim@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 May 2008 12:54:24 -0700 (PDT)
Hi,
We use transactions and the [Setup] and [TearDown] methods in NUnit.
You can begin the transaction in the Setup method, test whatever you
like to test in your test
and rollback the transaction in your TearDown method. If anything goes
wrong the db will complain.
If we want to test the result of a query, we do the same, but in our
test method we commit, assert the result, restore the database
by another commit and then begin a new transaction, in order to have
this empty transaction rolled back in the teardown method
and avoid an exception in the TearDown method.
If you have many testfixtures, you can derive all of them from a base
fixture, which for example begins and rolls back the transaction in
Setup and TearDown, so you
don't need to code this for each testfixture.
Joachim
.
- References:
- Best Way to Test Against a Database
- From: jehugaleahsa@xxxxxxxxx
- Re: Best Way to Test Against a Database
- From: Michael Justin
- Re: Best Way to Test Against a Database
- From: jehugaleahsa@xxxxxxxxx
- Re: Best Way to Test Against a Database
- From: Michael Justin
- Best Way to Test Against a Database
- Prev by Date: Re: Dealing with NULL collection in Linq query
- Next by Date: DateType that can be: True, False or Null?
- Previous by thread: Re: Best Way to Test Against a Database
- Next by thread: Re: Best Way to Test Against a Database
- Index(es):