|Top Previous Next|
Isolator++ allows you to replace behavior of existing method, by specifying an alternate implementation. If non of the Return methods work, this mechanism allows you to specify the exact behavior you need.
The DoInstead methods can be specified on static, global or instance methods.
You can do this using:
Assuming the following class is in the production code:
Let's replace the implementation of GetAge with our own implementation.
To do that, we'll create a function that will replace the original, in our own class (could also be the test class):
Note: The signature and calling convention of the replacing method should match the original method. When changing behavior of instance methods, you should use an instance method replacement:
The two arguments sent to DoMemberFunctionInstead are the replacement instance and the replacing method (no parenthesis).
Replacing static or global calls
Passing data to static alternative implementation
It is possible to pass extra data to the implementation, you pass the data in the second argument of DoStaticOrGlobalInstead and you grab it using the GET_EXTRA_DATA() macro.
Example where we will return the original age if the person is in group 5 or a fake age of 10.
Copyright © Typemock Ltd. 2009-2019. All Rights Reserved.