Assign value to property of mock object when method is called
263 views (last 30 days)
Hi, is there a way to assign a value to a property of a mock object when a method of the same object is called?
Let's say I create the following mock:
[mock, behavior] = createMock('AddedMethods', "doSomething", 'AddedProperties', "propA");
Now I would like to do something like:
when(withAnyInputs(behavior.doSomething), set(mock.propA, true));
Obviously, that's no valid code, but I think you get what I mean. Thanks for your help!
David Hruska on 10 Dec 2020
If you're using R2018b or later, you can use the Invoke action to set this up. Here's an example:
testCase = matlab.mock.TestCase.forInteractiveUse;
[mock, behavior] = testCase.createMock('AddedMethods', "doSomething", 'AddedProperties', "propA");
function obj = setPropA(obj)
obj.propA = true;
mock = mock.doSomething;