Search code examples
mockingmoqrhino-mocks

Why is mocking preferred with Interfaces?


I have been looking at examples of mocking using Moq and Rhino Mocks and all the examples seem to mock interfaces. Why is this? I have heard they can mock static classes, but what about non-static classes?


Solution

  • Because:

    1. All methods on your object would need to be virtual in order to mock them
    2. Your mock would still need to execute the constructor of the real object, pass parameters and run the logic inside it, which can be painful.