Search code examples
iosobjective-cunit-testingocmockclass-method

Mocking class methods with OCMock not working


What's wrong with this code? Trying to make a class method return @NO, but it's returning @YES (the NSLog prints "1").

// Make the test think you don't have any internet
id mockFunctions = [OCMockObject mockForClass:[Functions class]];
[[[mockFunctions stub] andReturnValue:@NO] connectionAvailable];


NSLog(@"derp: %hhd", [Functions connectionAvailable]);

Solution

  • I had two copies of the class that was being mocked. By not including the .m file in the test target, everything worked fine.