Setting Default Behavior of a Faked Class |
Top Previous Next |
When faking a class, you can set the default behavior of all methods. You can also set a different behavior for a specific method.
auto a = Isolator(); auto fakeMyClass = a.Fake.Instance<MyPureClass>(FakeOption::<option>);
Example use of the HandleExceptionInTest flag with a Private method:
TEST_F(WhenToUse, HandleExceptionInTest) { // Arrange // create a fake under test that will call all original code but exceptions will be caught in this test auto a = Isolator(); auto underTest = a.Fake.Instance<UnderTest>(FakeOption::CallOriginal | FakeOptions::HandleExceptionInTest);
try { // Act a.Invoke(A:Member(&underTest, PrivateMethodThatWillThrow)); // Assert ASSERT_EQ(TRUE, FALSE); // fail test we expected an excpetion } catch (MyException& e) { // Assert // can verify exception if needed } } |
Copyright Typemock Ltd. 2009-2025. All Rights Reserved.