I would like to test an NSOperation subclass. I tried to do this in my SenTestCase subclass:
- (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 the tests finishes before the NSOperation finished executing, despite specifying waitUntilAllOperationsAreFinished.
Any ideas of how to prevent the test from finishing before my operation completed?
You need to call waitUntilAllOperationsAreFinished after you added the operation to the queue, not in setUp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With