I am unit testing a c++ class and using Google Test and Google Mock frameworks.
For example,
I have a class which has non-virtual functions and I want to mock these two functions which have external dependencies.
I don't want to change my class A
(using gmock template way solution and dependency injection). Below can be two solutions probably:
- Simply mock on fly or any other option like we have in Python where we create
MagicMock()
and patch. - derive non-virtual class from the test class and wrap the non-virtual function by making it virtual in the test class, then call the prod non-virtual function.
class A
{
public:
bool DBConnect(string username);
private:
bool someWork(int);
};