Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing with Data Access Layer

what is a good way to write unit tests with a LINQ to SQL DAL?

Currently I am doing some database testing and need to create helper methods that access the database, but I don't want those methods in my main repo's.

So what I have is two copies of the DAL, one in my main project and one in the Test project. Is it easier to manage these things if I create a separate project for the data layer? I'm not sure which way is a better way to approach this.

If I do create a data layer project would I move all my repo's to that project as well? I'm not sure how to properly setup the layers.

Thanks

like image 825
chobo Avatar asked May 05 '10 18:05

chobo


1 Answers

I would use the Repository Pattern outlined in the September 2009 article in Visual Studio magazine titled "Eliminate Database Dependencies in Test-Driven development". I have been using this pattern since I read the article with great success. This pattern will help to decouple your data layer and write good unit tests.

This will require you to adopt an n-tier architecture and create a separate data layer, but in the long run it is worth it.

Here is a link to the online article. Repository Pattern

like image 90
Jason Jones Avatar answered Sep 21 '22 06:09

Jason Jones