In .NET, TypeMock Isolator and Microsoft Moles allow one to isolate any class, property, or method - be it sealed, static, protected or non-virtual. So what was impossible t
Not at all. From a purely technical point of view the interfaces are not strictly necessary. The only requirement for a mocking framework to construct a mock is that a method is virtual and the type has an accessible constructor. I utilize it quite a bit when I know that a particular class will not have multiple implementations.
I prefer doing TDD with a normal Castle Dynamic Proxy based mocking framework. It is all about creating a loosely coupled system with appropriately placed testing seams. Those testing seams could in future become extensibility points. The requirements placed by mocking considerations reinforce good design practices, causing more focused classes to be written.
Irrespective of unit testing coding to interfaces helps provide a loosely coupled system allowing you to slide modules in and out relatively easily be it swapping one for the other or some sort of configuration.
That aside there are many, my self included, that would say that TypeMock and the like that allow you to mock statics allow for bad practices. Others would say we live in ivory towers and that TypeMock allows you to get on and get things done. I don't hesitate to think that perhaps both are right and wrong depending on your point of view and what you want to achieve. I myself will continue to use interfaces and RhinoMock, NSubstitue or Moq at a push.
As you can see from these posts Good Design is not Subjective and Design And Testability from 2008 to 2010 it is still a hughly debated subject as you can see from the comments.
This is indeed an interesting question, which I sometimes heard from testing newbies. In my opinion, Moles/Typemock are not really comparable to mocking frameworks, and they are surely not a replacement. Here are my top arguments for it:
Conclusion:
Even Roy Osherove, the lead dev of Typemock, puts it that way (hopefully he's not getting into trouble with his boss because of this): A customer switches to MOQ – and I’m happy
There's one exception, though: If learning Test-driven development from scratch, it may be beneficial to use Typemock even for new code. This way, you can significantly flatten the TDD learning curve...
Thomas
But then we are back to the situation of having added production code complexity for basically the ability to unit test.
But that's not the reason you do it. You do it because otherwise the code has a hard dependency to an external element. Like a very simple specific implementation of a mail sender.
You isolate the external functionality behind simple contracts, that makes the rest of your code simpler / not more complex. You very clearly see the dependencies the code has, instead of those being hidden in the internals of the code.
You now have a simple mechanism to change those dependencies. There is less resistance when you end up needing to modify those contracts, that when the code is all mixed up in a chatty conversation in the internals of the class.
This is something that's hard to explain in the context of a simple stackoverflow question, specially as it usually takes a very long time for good design concepts to really sink in (if they do ...). I suggest reading about SOLID here.
Replacing like that with TypeMock has its place. To test legacy code that's not properly design, and maybe a handful other scenarios.