I want to test my Entities that are built using Entity Framework. My concern is that using Entity Framework means directly working with data source. So any ideas how to unit testing Entity Framework based components?
Apparently it's very hard. Eloquently put by Erik here - http://stackoverflow.com/questions/316897/tdd-and-adonet-entity-framework#answer-316972
How about using a mocking framework? It seems to me that a mocking framework can help you isolaye your business logic from the database.
I agree, a mocking framework is what you're after. You create "mocked" objects that aren't retrieved from your datasource, and you test the data in that object. I personally have been working with Moq, and I like it--there is also Rhinomocks, plus others.
You are going to want to use a Mocking Framework to retrieve mock values rather than hitting the real data. Here are a list of a few mocking frameworks and links to some screencasts to help you get started:
Here are some screencasts on how to get started:
I wonder how Mock would serve instead of database!! But I would give it a try thank you all.
Although the examples might be very simplistic I have attempted to discuss a possible solution to this very issue. It involves separation of concerns and our dear friend Dependency Injection.
Contact me if you want more details.
I would like to share another input to this. I was able to test Entity Framework based components and application using TypeMock Isolator as well. However it is commercial.
Have a look at this post: Introducing Entity Framework Unit Testing with TypeMock Isolator
Due to the fact that version 1 of the Entity Framework breaks a few major software design principles, there really isn't any way to apply TDD when using it in your application. My research points to NHibernate if you're looking for an immediate solution. It was designed with unit testing in mind.
However, if you can wait, there appears to be hope for the next release of the Entity Framework: Test-Driven Development Walkthrough with the Entity Framework 4.0
For Enity Framework 4, this looks promising: Testability and Entity Framework 4.0
The BookLibrary sample application of the WPF Application Framework (WAF) project shows how an Entity Framework based application can be unit tested.