是否可以将XCTest中使用的队列从com.apple.main队列更改为不同的队列?我在测试也调度到这个队列的应用程序时遇到了问题,因此不会进入dispatch_async块。这种现象显然与测试人员阻塞的已用队列有关。有没有办法改变XCTest测试器中的"dispatch_get_current_queue“输出?
语言: Objective C
XCode: 6.0.1
XCTest:与iPad上的主机应用程序集成测试
目标操作系统: iOS 7.1和8
发布于 2014-11-12 21:22:03
下面是我运行异步单元测试的方式
将此宏添加到单元测试之上。
// Macro - Set the flag for block completion
#define StartBlock() __block BOOL waitingForBlock = YES
// Macro - Set the flag to stop the loop
#define EndBlock() waitingForBlock = NO
// Macro - Wait and loop until flag is set
#define WaitUntilBlockCompletes() WaitWhile(waitingForBlock)
// Macro - Wait for condition to be NO/false in blocks and asynchronous calls
// Each test should have its own instance of a BOOL condition because of non-thread safe operations
#define WaitWhile(condition) \
do { \
while(condition) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
} \
} while(0)所以测试可以写成这样
- (void)testContentNode
{
StartBlock();
[AFContentNode loadContentWithUUID:@"d6d87899-94d4-4540-aeab-e88647e4ad61"
completion:^(AFMagnoliaNode *node, NSError *error)
{
XCTAssert(!error, @"Error raised: %@", error);
XCTAssert(node, @"Node has not been fetched");
EndBlock();
}];
WaitUntilBlockCompletes();
}https://stackoverflow.com/questions/26887312
复制相似问题