0

I am doing a TDD project using EF. I want to unit test the insertion operations I make. How should I do that?

What I have in mind;

  1. In the unit test, I can query the database if my insertion was successful.

  2. I can depend on other methods on my business library to check back if the insertion was successful, but I think that violates the purpose of the UNIT testing.

What are your suggestions?

Or should I use a mock framework, like Moq?

2 Answers 2

1

This is really integration testing not unit testing, normally with TDD i test to the boundries of my system, ie to the up to but not including the component which actually calls the external system. An example of this method can be found here: http://dl.dropbox.com/u/37129059/StaticVoid.Repository.Demo.zip using my repository framework (http://blog.staticvoid.co.nz/2011/10/staticvoid-repository-pattern-nuget.html).

Having said this its also valuable to do integration testing, especially on larger projects, whether this is via automated UI testing or some other means.

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

Comments

1

What you are trying to do is called integration testing, not unit testing. The only purpose one would want to test how ORM behaves, is to check whether mapping works. So your test case is perfectly valid. What you should do is just create your entity object, save it in DB. Fetch back persisted object and compare to the entity object you just created. If all fields/properties are equal, EF mapping works fine.

1 Comment

Actually you are right, this is my first project witj EF. So I wanted to test the way I use it.

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.