Caveats
What can I mock?
- You can mock any interface.
- Your mock class must have a default constructor -- either no constructor or one with no arguments. It is your responsibility to make sure that this constructor does not throw an exception.
- If the interface or class is templated, you can mock any instantiation of that template. That is, you can mock List!(int), but you can't mock List!(T) (unless the test is templated by T).
- You cannot mock a struct, a union, or a free function.
What methods can be mocked?
- Public or protected virtual methods can be mocked.
- Private methods are final and are not mocked.
- Templated methods are final and thus not mocked.
Anything else?
- Creating a mock means creating a new class. This class inherits from whichever you just mocked. So the easiest way to get around mock objects is for the tested class to call constructors.
- Avoiding that problem means writing a lot of factories, which is another problem. You can fix this if you take a look at DConstructor.
back to the main page
