单元测试 NSOperation?
我想测试 NSOperation
子类。我尝试在我的 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
}
但是,尽管指定了 waitUntilAllOperationsAreFinished,但测试还是在 NSOperation 完成执行之前完成。
关于如何防止测试在我的操作完成之前完成的任何想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在将操作添加到队列后调用
waitUntilAllOperationsAreFinished
,而不是在setUp
中调用。You need to call
waitUntilAllOperationsAreFinished
after you added the operation to the queue, not insetUp
.