I had a question today about whether you could just mark methods as virtual on a concrete class so they could be mocked, or if you should just extract an interface and mock that. In a statically typed language like C# the safest answer in my book is to extract an interface. Here’s a bit of a reprint from an earlier post on this subject with some additional highlighting:
I would urge a certain level of caution in mocking an abstract class or a concrete class. For best results my advice is to only mock interfaces to avoid unwanted side effects. It is certainly possible to mock an abstract class, doing that leads to some side effects that effectively negate all of the advantages of a mock object. Dynamic mock object tools like NMock or Rhino Mocks can only override virtual methods. This might not be so much a problem in other languages, but with the .Net languages all methods are non-virtual by default. This means that some of the behavior that you were trying to remove from the test with a mock is still there. The dynamic mock libraries work by using Reflection.Emit to create a dynamic proxy on the fly for the requested interface or abstract class. In the case of an abstract class the dynamic mock can only intercept virtual members and even worse, the constructor function of the superclass will probably be exercised.