Unit Test NSOperation?

I would like to test a subclass NSOperation. I tried to do this in my subclass SenTestCase:

- (void)setUp {
    [super setUp];

    _importQueue = [[NSOperationQueue alloc] init];

    [_importQueue setMaxConcurrentOperationCount:1];
    [_importQueue waitUntilAllOperationsAreFinished];
}

- (void)tearDown {
    [_importQueue release];

    [super tearDown];
}

- (void)testSomeImport {
    ImportOperation *op = [[ImportOperation alloc] initWithFile:...];
    [_importQueue addOperation:op];
    [op setDelegate:self];
    [op release];
}

- (void)opDidFinish:(ImportOperation *)op {     // ImportOperation delegate method
    // Not getting called
}

But tests end before completion NSOperation, despite the indication waitUntilAllOperationsAreFinished.

Any ideas on how to prevent the completion of the test before the completion of my operation?

+5
source share
1 answer

You need to call waitUntilAllOperationsAreFinishedafter adding the operation to the queue, not to setUp.

+12
source

All Articles