Let me start by saying Shims are evil. But they are evil by design. They
let you do things you otherwise couldn’t do, which is very powerful. They let
you do things you might not want to do, and might know you shouldn’t do, but
because of the real world of software, you have to do.
The Catch-22 of Refactoring to Enable Unit Testing
In the first part of my series on VS11 Fakes, I reviewed Stubs, which are
a simple way of creating concrete implementations of interfaces and abstract
classes for use in unit tests.
But sometimes it happens that you have to test a method where the dependencies
can’t be simply injected via an interface. It might be that your code depends
on an external system like SharePoint, or simply that the code news up or uses
a concrete object inside the method, where you can’t easily replace it.
The unit testing agilista have always said, “Refactor your code to make it more
testable,” but therein lies the rub. I will again refer to the esteemed Martin
Fowler for a quote: