[英]Unit Test NSOperation?
I would like to test an NSOperation
subclass.我想测试一个
NSOperation
子类。 I tried to do this in my SenTestCase
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 the tests finishes before the NSOperation
finished executing, despite specifying waitUntilAllOperationsAreFinished
.但是测试在
NSOperation
完成执行之前完成,尽管指定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
.将操作添加到队列后,您需要调用
waitUntilAllOperationsAreFinished
,而不是在setUp
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.