开发者

Unit Test NSOperation?

I would like to test an NSOperation subclass. I tried t开发者_StackOverflow社区o 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜