Hippomocks' MockRepository
supports multiple instances as far as the compiler is concerned. Some use cases are not possible, though, as they lead to unit test executable crash. Let's consider the following example.
void MyCall()
{
}
void MyCall2()
{
}
void MySubTest()
{
MockRepository mockRep2;
mockRep2.ExpectCallFunc(MyCall2);
MyCall2();
}
void MyTest()
{
MockRepository mockRep1;
mockRep1.ExpectCallFunc(MyCall);
MySubTest();
MyCall();
}
This example leads (in Visual C++ 2010) to an unhandled exception (access violation reading location 0x00000048).
- Analyzing the Hippomocks header shows that this use case doesn't seem to be foreseen (cf.
MockRepoInstanceHolder
). What is the reason behind allowing only one instance? - I can understand that for example different
ExpectCallFunc
in theMockRepository
instances can contradict. Is it the reason behind it? - We could solve the problem in our example by moving the
mockRep1
instantiation to after theMySubTest()
call, but we had a hard time understanding the problem in a first place. Is there a compile-time or run-time possibility to identify such multiple instances explicitly?