WillBeIgnored Behavior

Top  Previous  Next

In some cases, you may need to fake a method that doesn't return any value (a void method). For such methods, you can use the WillBeIgnored() API. This is particularly useful when you want to mock the behavior of a method that doesn't return anything but may still have side effects, such as setting values or triggering other actions.

You can use WillBeIgnored() on both live instances and fake objects, allowing you to fake just one of the methods of a live object while keeping the rest of its behavior intact.

 

TEST_F(Examples, FakingVoidMethods)

{

  // Arrange

   auto a = Isolator();  

   Address address;

   

   a.CallTo(address.SetCountry(A::Any())).WillbeIgnored();

  

   // Act 

   address.SetCountry("Antartica"); // This will be ignored

   // continue with test

}


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