是否可以形成对象的局部模拟,该对象已经是另一个对象的局部模拟,即可以嵌套部分模拟?
// ... outer method
MyClass *myObjectSaved = myObject;
id mockMyObject = MCPartialMock(myObject);
OCMStub([mockMyObject flag]).andReturn(YES);
// ... call to inner method (several other calls in between)
// pass in mockMyObject as myObject
// (it should not have to care whether it receives object or its mock)
id mockMyObject = MCPartialMock(myObject);
OCMStub([mockMyObject flag]).andReturn(NO);
// ... tests inside inner method
[mockMyObject stopMocking];
// ... return from inner method
[mockMyObject stopMocking];
原型建议内部方法中的stopMocking
删除整个模拟状态,即当内部方法返回外部方法myObjectSaved
时,不再报告为OCMockObject(MyClass)
,而是MyClass
1}}。
那么可以用OCMock 3嵌套部分模拟吗?