Click here to Skip to main content
12,501,105 members (41,899 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# NUnit

I have a data layer which returns List
Posted 6-Oct-11 14:32pm
Updated 6-Oct-11 14:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are different ways you can perform unit testing of DAL.

Option 1: In-memory database
Using an in-memory database and for testing run all the tests agains it. It is best if you can choose an in-memory database with which offers almost similar syntax as the actual database you are using.

Option 2: Mocking the ADO.Net
OleDbConnection has an underlying interface IDbConnection
OleDbCommand has IDbCommand and so on.

You can use DI, automatic using containers or manual or a factory implementation would also do, to inject the right dependency depending at runtime.

Option 2 could be an expensive choice, I suggest take it only if your DAL has to resolve complex hierarch / dependencies.

Option 3:
Follow the link
Unit Testing the Data Access Layer[^]

Unit Testing the Data Access Layer 2[^] see if this suites your need.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

There is no correct way of writing test and most of the time efficiency is of no concern as the tool is doing all the work.

You must note that writing great tests is not the goal, but the goal is writing great software so the test are only there to support the main code.

Principals to follow in writing test:

1) They should be repeatable, so you must have setup and cleanup code before and after.
2) Be as granular as you need to be, its better to test a specific feature than to test everything at once.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 7 Oct 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100