mercredi 27 mai 2015

Testing asynchronous call in unit test without block parameter

I have read through below discussions about testing asynchronous call in unit test

  1. Testing asynchronous call in unit test in iOS
  2. How to unit test asynchronous APIs?
  3. http://ift.tt/1jzQL6R.

All of them need a block parameter in the original function, my question is how to test asynchronous call without the block parameter.

Here is the function I want to test. Since this function don't have a completion handler block, I can't add __block BOOL done or [documentOpenExpectation fulfill] to unit test that mentioned in above discussions.

-(void)function {
    NSManagedObjectContext *childContext = [[[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType] autorelease];
    childContext.parentContext = self.managedObjectContext;
    [childContext performBlock:^{
        // Do something
    }];
}

Aucun commentaire:

Enregistrer un commentaire