In .net, unlike in Java, methods are not virtual by default. In order to use most mock object frameworks, you either have to mark the methods that you want to use on your mock as virtual on the `real' object, or you have to have an interface that you can mock that the class under test will accept in lieu of the implementation.
It seems like bad form to go and mark every method as virtual, but it also seems like bad form to define an interface for every single class.
What is the best thing to do?
If I have to choose between the two, I'd go with the interface thing. An interface is meant to define a contract, which is basically what a mock object is going to adhere to. Marking a method as virtual might have unanticipated side effects. It affects the design of the actual class being mocked. An interface merely defines method names and will have no effect on the real class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With