Setting Default Behavior of a Faked Class

Top  Previous  Next

When faking a class, you can set the default behavior of all methods. Then you can set a different behavior for a specific method.

 

MyClass* fakeMyClass = FAKE<MyClass>(FakeOption::<option>);

 

Fake Option

Behavior

FakeOption::Recursive

This is the default behavior when faking an object. 

Methods will return:

·For object types: Fake objects
·For other return types: Zero or equivalent

This ensures that 

FakeOption::CallOriginal

Calls to fake object methods will pass through the original implementation. Constructor is called during object's instantiation.

Useful when you want to maintain original behavior and modify specific methods.

FakeOptions::HandleExceptionInTest

Tells Isolator++ that exceptions are caught in the test code as opposed to be caught in the under test code.

Note: This is for 64 bit only.

 

Example use of the HandleExceptionInTest flag with a Private method:

 

TEST_F(WhenToUse, HandleExceptionInTest)

{

   // create a fake under test that will call all original code but exceptions will be caught in this test

   auto underTest = Fake<UnderTest>(FakeOptions::CallOriginal | FakeOptions::HandleExceptionInTest);

   

   try

   {

       ISOLATOR_INVOKE_FUNCTION(_, &underTest, PrivateMethodThatWillThrow);

       ASSERT_EQ(TRUE, FALSE); // fail test we expected an excpetion

   }

   catch (MyException& e)

   {

       // can verify exception if needed

   }

}


Copyright  Typemock Ltd. 2009-2025.  All Rights Reserved.