views:

87

answers:

2

I want to test the data layer, how do I go about this? I am using NUnit for my business object testing. Must I use mock objects (which I have never used before)?

I would appreciate any amount of input if someone can just guide me in the right direction.

+1  A: 

Using mock objects depends upon your unit tests. If you dont want to initialize many objects for testing a single object you can use a mock to simulate the behavior of the other objects.

For testing DAL objects you will have to reset the DB State every time you run a test. As running tests on your database will create many records which might change the state of the DB.

Hemanshu Bhojak
+2  A: 

You would have to do this:

  1. Separate your business layer ( or controller layer) away from your data access. Make sure that your data access layer is fully clean. You need mock to do this.
  2. If you are using an ORM such as NHibernate, change the database vendor to something that's light ( such as sqlite, set it to in-memory in the config) so that you can execute the tests against an in-memory database. In this way, you don't have to worry about messy things such as resource cleanup. Of course, you need to prepopulate your data before doing your tests.

Here's an answer on unit testing DAL that you might find useful.

Ngu Soon Hui