I am new to OCMock .
I use dispatch_once()created a singleton class MyManager:
@implementation MyManager
+ (id)sharedInstance {
static MyManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
I have a method in a class Schoolthat uses the singleton above:
@implementation School
...
- (void) createLecture {
MyManager *mgr = [MyManager sharedInstance];
[mgr checkLectures];
...
}
@end
Now, I want to unit test this method, I use the partial MyManager layout:
- (void) testCreateLecture {
id partialMockMgr = [OCMockObject partialMockForObject:[MyManager sharedInstance]];
[schoolToTest createLecture];
...
}
I noticed that with OCMock, after creating a partial layout of my singleton instance, MyManagerwhen I run my test method, it automatically uses the partially fabricated instance.
This is a little strange for me, since in my test example above I only created a partial layout of the instance MyManagerwithout entering it into the class MyManager,
OCMock , [MyManager sharedInstance] ? - ?