Faking concrete classes
|Top Previous Next|
With Isolator++ Professional, you use the same syntax for changing the behavior of any classes, including concrete ones.
Let's say we want to change the behavior of a concrete method:
We'll use the following code
First, we're creating a fake object using the FAKE API. This fakes all the methods on the MyClass class. Primitives return 0, and methods returning pointers, return pointers to fake objects. To further change specific methods, we used the regular WHEN_CALLED API to declare the behavior we want. In this case, we're returning the value 10.
For example if we Fake all the methods of MyClass, but want the constructor to be called.
We'll use the following code:
First, we're fake a MyClass object. Then we're call the constructor using the ISOLATOR_INVOKE_CONSTRUCTOR API with specified constructor arguments, 1 in this case. You can use ISOLATOR_INVOKE_CONSTRUCTOR for public and private constructors.
Note: ISOLATOR_INVOKE_CONSTRUCTOR can be called only once per object's lifetime.
See Faking methods called in constructor for more usages
Copyright Typemock Ltd. 2009-2023. All Rights Reserved.