We always use OCMock in the following way, but it seems doesn’t work for some read only property variables, such as NavigationController and so forth, it is read only, set mock one doesn’t take effect.
Have you ever experienced this tough issue, how do you solve it? Any idea will be appreciated, thanks in advance you smart guys.
id mockWebView = [OCMockObject mockForClass:[UIWebView class]];
[[mockWebView expect] loadHTMLString:...];
object_setInstanceVariable(viewController, "webView", mockWebView);
Use a partial mock:
This won’t work if viewController accesses the ivar directly, but it will if it accesses the ivar through the accessor:
self.webview, which is generally how you should access properties.