OCMock an NSOperation

前提是你 提交于 2019-12-05 12:56:51

If you're using ARC, operation is probably released right after you create the mock, as it's not accessed again. If you change it to this, it should fix the error:

[queue addOperation:operation];

...which you should be doing anyways--you're testing your object, not the mock.

When using ARC the reference to the object in mockOperation will be set to nil quite aggressively (too aggressively I think) by the Apple runtime. Not all is lost, though. You can set up your stubs and expectations using mockOperation and still pass operation to the addOperation: method; the partial mock works even when you use a reference to the original object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!