Why You Need an Isolation Framework

This brought me back about 4 years ago, when I was hand-writing  mocks. I knew there were tools out there for dynamic mocking, but I figured, hey, I can write these myself, I have full control, I wouldn’t need to learn another framework. And I wasted time and money on it.

Case in point. If you have VS 2008 SP1, you have the web MVC project template. It creates a small project that actually runs. Create a new project, and the wizard will ask you to generate tests. Of course, you say. So the code for tests is generated, and a lot of code is generated for mock objects. A lot.

How much?

The code in the AccountControllerTest file contains 25 tests. All of them call the GetAccountController method, (which is basically the setup for all mocks) and following this method, appears all the mocking code.


The mocking code starts at line 368 and goes on until line 653 (the end of the file). That’s 285 lines of mocking code, some of it contains logic.

Now I replaced this hand-rolled mocks with Isolator code. The GetAccountController method now looks like this:

image You may notice that the method is a bit longer. However, you may also notice the file, containing the same 25 tests, ends at line 381. I’ll let you do the math. You can download the solution from here.

I wrote mock code like that before. Can you believe my mocking code even contained bugs? I had to fix those as well.

It’s a waste of time. Start using an isolation framework now.