I’ve started to use GTest (Google Test) for a C++ project I’m working on. I have one class that depends heavily on MFC (CFile, CObject, CString, etc.).
How can I break the dependencies on MFC (or minimize them) so I don’t have to create dummy MFC objects just to run my tests? I want to test what my methods do not MFC functionnalities.
Here is an example of the kind of method I have to test :
// DumpContext class inherits from CDumpContext
void MyClass::Print(DumpContext &dc)
{
// MyClass::Print real work goes here :
...
}
As far as I can understand, the fact that MFC lacks interfaces makes it difficult to mock.
As an alternative you can inherit from a dependency and try to make the best out of it.
In your example you can use the already existing CMemFile which doesn’t require anything when constructing and lets you access the result.
In other cases you have to invent something similar yourself.