Currently working on writing out some test for an iOS enterprise application. My concern is in this set up of my overloaded constructor.
- (id)init
{
CRMHttpClient *client = [CRMHttpClient sharedClient];
NSOperationQueue *queue = [NSOperationQueue new];
UIApplication *application = [UIApplication sharedApplication];
return [self initWithCRMHttpClient:client operationQueue:queue application:application];
}
- (id) initWithCRMHttpClient:(CRMHttpClient *)client operationQueue:(NSOperationQueue *)operationQueue application:(UIApplication *)application
{
self = [super init];
if(self)
{
self.client = client;
self.queue = operationQueue;
self.queue.name = [[NSBundle.mainBundle bundleIdentifier] stringByAppendingString:@".CRMDataProcessingQueue"];
self.queue.maxConcurrentOperationCount = 2;
self.application = application;
self.backgroundTask = UIBackgroundTaskInvalid;
}
return self;
}
-(id)init
is called by the other classes in the project. -(id)initWithCRMHttpClient:...
is called in my test class so I can inject my mocks to unit test my class. (I know I could use partial mocks for the singleton classes, but I prefer to explicitly inject the class)
What bothers me about this approach is the few lines of code where I'm configuring my NSOperationQueue
's name and operation count. This requires me to write this up in my -(void)setup
method of my testing class.
- (void)setUp
{
[super setUp];
self.mockCRMHttpClient = [OCMockObject mockForClass:[CRMHttpClient class]];
self.mockOperationQueue = [OCMockObject mockForClass:[NSOperationQueue class]];
[[self.mockOperationQueue stub] setName:OCMOCK_ANY];
[[self.mockOperationQueue stub] setMaxConcurrentOperationCount:2];
self.mockApplication = [OCMockObject mockForClass:[UIApplication class]];
}
I need to stub out the calls for those set up methods so that I don't get failed calls. I my options are:
- Leave it as is, stubbing in the
-setup
- Configure the operation queue in the
-init
method instead. - Create a nice mock for
mockOperationQueue
- Am I forgetting something?
I'm unsure of which approach to take.