Sequencing behaviors

Top  Previous  Next

If you'd like a fake function to return different values on different calls, you can easily do this by doing WHEN_CALLED->Return() combos sequentially:

 

TEST_F(BehaviorSequencingExamples, ReturnTwiceReturnsValuesByOrder)

{

   ConcreteClass* fakeCOncrete = FAKE<ConcreteClass>();

   

   WHEN_CALLED(fakeConcrete->GetString()).Return("hello");

   WHEN_CALLED(fakeConcrete->GetString()).Return("world");

   

   ASSERT_EQ("hello", fakeConcrete->GetString());

   ASSERT_EQ("world", fakeConcrete->GetString());

   ASSERT_EQ("world", fakeConcrete->GetString());

}

 

 

The first call returns the first value. Because of Isolator++ Professional's sticky behavior, the last WHEN_CALLED will continue on until ISOLATOR_CLEANUP is invoked.


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