3. Three ways. In the test code, create an instance of MockClassToBeMocked and pass that instance into...
(a) ClassToBeMocked's constructor. Your PRODUCTION code would be calling that same constructor, but
passing an instance of ClassToBeMocked into the constructor. This means there needs to be a
member variable to hold onto that object, and the MethodToBeTested uses that member variable
to call this->anInstanceOfClassToBeMocked->MethodToBeMocked();
corrected code:
ClassUnderTest::ClassUnderTest(ClassToBeMocked* anInstanceOfClassToBeMockedIn)
{
this->anInstanceOfClassToBeMocked = anInstanceOfClassToBeMockedIn;
}
ClassUnderTest::MethodToBeTested()
{
... other code
this->anInstanceOfClassToBeMocked->MethodToBeMocked()
... other code
}
--------- or ----------
ClassUnderTest::MethodToBeTested(ClassToBeMocked* anInstanceOfClassToBeMocked)
{
...other code
anInstanceOfClassToBeMocked->MethodToBeMocked()
...other code