Tuesday, April 10, 2007

TypeMock too powerful to use

In my early stages of following TDD light I was looking for a mock object framework. I tried Rhino.Mocks and found it hard to use. Then I tried TypeMock and falled in love with the product. It allows mocking almost anything. With TypeMock I only failed to mock SqlDataReader because it doesn’t have a public constructor.

It was then. Today I believe that TypeMock is bad for the same reason I loved it before. It’s too powerful. It doesn’t force you to write a testable code.

The reason I found Rhino.Mocks hard to use is because I haven't learn yet about Inversion of Control Containers and the Dependency Injection pattern. Today I write my own mock objects without using any framework. However, if you want to use a Mock Framework, I strongly recommend Rhino.Mocks.

If you're not familiar with this pattern I recommend to read Jeremy Palermo's article Simple dependency injection to get you started with unit testing.

1 comment:

Colin Jack said...


I haven't use Rhino.Mocks for a while but from what I can remember it could mock delegates, interfaces and virtual methods. I thus found I was either making all the methods virtual or was introducing interfaces, even though those interfaces were pretty much useless for anything other than testing.

In fact I found designing for testability can actually cause me to write slightly poor code, but I guess it depends on the situation.