W开发者_运维技巧hat's the difference between mocking classes and interfaces in Rhino Mocks?
You can't mock concrete classes per se, unless the class is abstract or has virtual methods. You can fake the contract of the abstract class, or override virtual methods with a faked method using Rhino Mocks.
Mocking an interface simply means you are defining a fake implementation of said interface.
To mock a class the properties and functions need to be declared as virtual. When mocking an interface your can mock freely without problem.
Further it is possible to run code that is not mocked if you mock a class, this can't be done if you are mocking an interface. Let's say that you want to check how your class is functioning when a specific function returns a certain value you might have to mock a class. I'd recommend staying with mocking interfaces as far as possible though. It is much much easier.
精彩评论