Discussion Locked

Erik Jacobsen

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
blog root

2 replies

by erikjacobsen1

Having a VB.NET class fetching and saving data from and to a database, I need to set up some Nunit testing.

Some methods return a DataSet, some simple values.

How do you run Nunit-tests on a database? I've come
up with these things to consider:

1) Start with an empty test-database
2) Populate with known data
3) Each test may add data when testing, but
must remove it to keep the original state
4) Write (or find) a CompareDataSet-method to
test these

I wrote a simple CompareDataSet-method myself,
and I'm about to implement the 4 things above
(or rather have someone else do it...)

We'll need to change the database connector
shortly, and a good Nunit-test should show us
if the new version works the same way.

Is this the way to do it? I'll tell you later.

by erikjacobsen1

So it worked. Actually. We had a NUnit test fail, when it wasn't
supposed to. It's never supposed to fail, of course, but it can be
unexpected. Turned out that we had missed an "ORDERED BY" clause.

In MSSQL primary keys are usually clustered, meaning more or less that
selects will always return the records ordered by the primary key. Not
so in MySql, which requires you to add the "ORDERED BY". A lesson for
the future: it's best to specify your ordering, even if the default is
fine. Any decent SQL will optimize it away if it's not needed, and you
will get portable code.

This discussion is closed to new replies.