Muhammad Mosa prepared a presentation on examples for unit testing EF apps. Entity framework has been considered hard to test, but Muhammad shows how to do it easily with Typemock Isolator. You can download the presentation and code and try it for yourselves.
You can also follow Muhammad on Twitter, and I suggest you do!
Many enterprise software applications today include databases. It doesn’t matter what kind of database is used, or whether you have a client-server application, or a multi tiered application. When it comes to complex systems, as these applications are, testing becomes hard – Tests now encompass the entire system!
That’s not good for unit testing. Imagine that you are writing a test for a component in the business logic. It calls the DAL (Data Access Layer) and then the database. Now, this test requires some kind of data setup in the database. That’s fine. Now for your second test, this one requires a second setup! What if you’ve got 1000 tests? Each test requires a setup step and a cleanup step, to return to the original state. That’s a lot of work.
But that’s not the only problem. When you run your test, it takes them time to run. Let’s say 0.1 seconds. For the entire suite: 100 seconds. Would you wait this time to know if all your tests passed? Maybe once or twice but not more since it’s counter-productive. And if you don’t run your tests, why should you write them?
At that point, you’re right back where you started – working without a safety net. There’s got to be a better way, and that’s where Typemock comes in.
Typemock Isolator allows you to isolate your code from dependencies like your database. Your setup now becomes easier, since you don’t need to set up an entire database, just what you need for your test. And since the tests run in-process, they are now running much faster.
Isolator also lets you decide where you want the isolation point is. If you’re asking the business logic, you probably can fake the DAL objects. If you’re testing the DAL components, you can isolate the database calls. And if you’d like to test the business logic and the DAL together, you can do that as well. You decide what to isolate based on your test.
There’s no need for heavy, lengthy setup. Use Isolator to easily write tests for your enterprise software.