I am currently using HippoMocks as mocking framework, and can’t figure out how to mock the pure virtual method MockMe() in the code below. I do not want to mock any of the non-virtual methods (which is likely not even possible), instead I want them to do what they are meant for and call the mocked virtual one.
struct A
{
void Run() { RunImpl(); }
virtual void RunImpl() = 0;
};
struct B : public A
{
//implement A::RunImpl
void RunImpl() { MockMe(); }
//this one I want to mock
virtual void MockMe() = 0;
};
MockRepository mocks;
B* b = mocks.InterfaceMock< B >();
mocks.OnCall( b, B::MockMe );
b->Run(); //throws NotImplementedException for Run()
Is there any way to get this working with HippoMocks? Or with another framework? Or with some source modifications?
update/answer: I found a way around it by deriving a new class from B and adding a helper to forward the calls to the appropriate method. Apart from that it’s also important to use
ClassMockinstead ofInterfaceMock.So, using the example above, this works: