0

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
  • Can you tell a little about the DAL? Does it use LINQ-to-SQL, ADO.NET or something else? Can you please also tell what are the data objects you're working with? Last, what kind of things do you want to test - for example, the queries or way the data objects are built? Commented Dec 7, 2009 at 8:37

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.