One approach is to wrap a class method in a method of your own class. So let your class call [SomeOtherClass classMethod:someString] . You can create an invokeClassMethod: method in your class as follows:
-(NSString *)invokeClassMethod:(NSString *)someString { return [SomeOtherClass classMethod:someString]; }
Then, in your test, you create a partial layout and expect invokeClassMethod:
-(void)testSomething { id partialMock = [OCMockObject partialMockForObject:actual]; [[[partialMock expect] andReturn:@"foo"] invokeClassMethod:@"bar"]; [actual doSomething:@"bar"]; [partialMock verify]; }
If you want to verify that invokeClassMethod not called, you can throw an exception:
-(void)testSomethingElse { id partialMock = [OCMockObject partialMockForObject:actual]; [[[partialMock stub] andThrow:[NSException exceptionWithName:@"foo" reason:@"Should not have called invokeClassMethod:" userInfo:nil] invokeClassMethod:OCMOCK_ANY]; [actual doSomething:@"bar"]; }
Resolving will cause the test to fail if invokeClassMethod is invokeClassMethod .
source share