OC Mock not propagating into code - CocoaPod

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

OC Mock not propagating into code - CocoaPod

Postby boovius » 16 Sep 2014, 20:34

Hello,

I am not able to get my mocks made with OCMock to propagate into my implementation code during test.

I have installed OCMock into my iOS project with CocoaPods, and have tried tried multiple class mock and partial object mock implementations.

For instance:

IMPLEMENTATION CODE FOR MYCLASS
+ (int) returnsFive {
return 5;
}

IMPLEMENTATION CODE FOR MYCONTROLLER
#import "MyClass.h"

- (void) viewDiDLoad {
self.number = [MyClass returnsFive];
}

TEST CODE
id myClassMock = [[MyClass alloc] init]
OCMStub([myClassMock returnsFive]).andReturn(7);

NSLog(@"%@", [MyClass returnsFive]); // -- ((this prints out 7))

[MyController layoutIfNeeded] // -- ((runs viewDidLoad))

XCTAssertEqual(MyController.number, 7, @"the number property on MyController should be set to 7 after mock) // -- ((this fails, MyController.number equals 5 and not 7 as stubbed out))


CONCLUSION and PROBLEM
The class mock works when run in the test, however, when run in the implementation code, the mock does not carry over. The actual class (i.e. MyClass) gets run instead of the mock.

We have tried this with different variations of mocking (i.e. partial mocks on objects and using mocks on instance methods instead of class methods). All have yielded the exact same result where the mock does not propagate into the implementation code.

1.) Is this even possible? (it seems like it must be)
2.) Is there some setup step we are missing? (we installed OCMock with CocoaPods, and imported the framework into our testClass with #import <OCMock/OCMock.h>)
3.) Any ideas on how to solve our dilemma???
boovius
 

Return to OCMock



cron