chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,

I'm getting an exception when trying to fake an object. Here is my test

const QString ID = "MY_IDENTIFIER";

MyClass *fake = FAKE<MyClass>(FakeOptions::CallOriginal);
WHEN_CALLED(fake->success()).Ignore();

fake->myMethod(ID);

ASSERT_WAS_CALLED(fake->success());

Do I use FAKE wrong?

Regards,
James
asked by JamesKing (8.2k points)

1 Answer

0 votes
Hi James,

We have a feature just for this called Live Fakes.
Live-Fake is a situation when we declare a new "Live" object and using WHEN_CALLED on it which makes it
to has "Fake" behavior.

The problem here is that even though the fake is created with FakeOptions::CallOriginal the constructor of MyClass was not called which caused mHashMap to be empty and throw exception when it is accessed.

If it is possible you can skip the fake statement and create the object with standard call to the constructor.

void MyTest::myTest()
{
const QString ID = "MY_IDENTIFIER";

MyClass *fake = new MyClass(NULL);
WHEN_CALLED(fake->success()).Ignore();

fake->myMethod(ID);

ASSERT_WAS_CALLED(fake->success());
}
answered by Shai Barak (1.5k points)
...