OCMock 提供了一个很好的语法来模拟类方法,但是类方法调用可以转发到真正的类对象吗?
self.connectionMock = [OCMockObject mockForClass:NSURLConnection.class];
[[[[self.connectionMock stub] andDo:^(NSInvocation *invocation) {
NSURL *url = [invocation getArgumentAtIndexAsObject:2];
NSLog(@"Passing through mock: %@", url);
} ] andForwardToRealObject] connectionWithRequest:OCMOCK_ANY delegate:OCMOCK_ANY];
该问题andForwardToRealObject
仅适用于部分。我可以自己调整方法,但是有没有一种简单的方法可以让我使用 OCMock 调用原始类方法?