Intro:
I have the tool (Xcode 5.0.2), library (OCMock 2.2.1) and test (XCTest) setup mentioned in the title of this question.
Category:
I have a category on NSObject with a class method like this:
+ (BOOL) hasDeclaredPropertyWithName: (NSString*) property;
Issue with OCMock and XCTest framework?:
Now i have a simple test set-up where I'm mocking a simple value object, like this: (mocking value objects is a test smell, I know. but this is just for illustration purpose.)
- (void) testFoo {
id mock = [OCMockObject mockForClass: [TestObject class]];
[[[mock stub] andReturn: NO] hasDeclaredPropertyWithName: @"propertyX"];
[mock hasDeclaredPropertyWithName: @"propertyX"];
}
When the 3rd line of the test method testFoo is executed, I end up with the error:
-[NSProxy doesNotRecognizeSelector:hasDeclaredPropertyWithName:] called!
Question:
Why mocking a class method seems impossible with OCMock (At least with my setup)?
If i make hasDeclaredPropertyWithName
to an instace method like
- (BOOL) hasDeclaredPropertyWithName: (NSString*) property;
everything's working just fine!
Can someone explain this OCMock deficiency to me? Or do I have a major missconception regarding Objective-C here? :)
Is the category maybe causing headaches to the runtime and/or OCMock?
Btw., I didn't try this test with a class method inside TestObject
directly!