a.CallTo |
Top Previous Next |
To change the behavior and methods, use the CallTo API.
a.CallTo(myClass->PublicMethod()).<behavior>();
Setting the behavior
After describing the method to fake, choose the behavior by using one of the following APIs:
Depending on the type of function you'd like to change behavior of, you might need to call the following APIs first:
In the following example, we use CallTo to return a value on a live object.
TEST_F(Examples, UsingWhenCalled) { // Arrange auto a = Isolator();
Person* personPtr = new Person();
a.CallTo(personPtr->GetAge()).WillReturn(34);
// Act auto result = personPtr->GetAge();
// Assert ASSERT_EQ(34, result); }
Changing private methods
a.CallToPrivate(A::Member(myClass, PrivateMethod)).<behavior>();
See Faking private and protected methods
Changing overloaded private methods
a.CallToPrivate(A::Member(myClass, PrivateMethod),A::Type<bool>())).<behavior>();
Faking Method Chaining This is useful when you have a hierarchy of objects and you want to define a specific behavior for a chain of methods.
// GetPartner method returns A person a.CallTo(personPtr->GetPartner()->GetId()).WillReturn(10);
Note: Every method in the chain will get mocked.
Note: To fake Microsoft classes or if your methods return Microsoft types, download the PDB file from the Microsoft Server (See Local Debug Symbols)
|
Copyright Typemock Ltd. 2009-2025. All Rights Reserved.