Deep Chaining |
Top Previous Next |
With Isolator++ Professional, you can fake a chain of members in one command, making it especially useful for APIs where multiple objects return each other. This feature simplifies the process by allowing you to fake an entire chain without manually creating individual fakes for each member in the chain.
Note: Deep Chaining also supports Conditional Behavior Faking
When you use Deep Chaining, every method in the chain gets mocked and its behavior is set to default. If the method is void, it will instead be ignored.
Example
In this example, the GetLocation method returns a fake GPSLocation, even though it isn't explicitly faked in the test. The chained call GetLocation()->Latitude() is set to return 10, which is then used in the method under test, GetLocationLatitude.
TEST_F(Examples, SettingChainedMethodsBehavior) { // Arrange auto a = Isolator(); Person* livePerson = new Person(); Address * fakeAdd = a.Fake.Instance<Address>();
a.CallTo(fakeAdd->GetLocation()->Latitude()).WillReturn(10);
// Act auto result = livePerson->GetLocationLatitude(fakeAdd);
// Assert ASSERT_EQ(10, result); }
//The method under test int Person::GetLocationLatitude(Address* pAddress) { return pAddress->GetLocation()->Latitude(); } |
Copyright Typemock Ltd. 2009-2025. All Rights Reserved.