어떻게 비동기 단위를 실행 해요되어
을 테스트
단위 테스트 위에이 매크로를 추가하십시오.
// 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();
}
처럼 쓸 수있는 testhost (통합 테스트)를 테스트 할 때이 일을합니까? 아니면 시뮬레이터를 사용합니까? – Simon
시뮬레이터를 사용하고 있지만 testhost에 문제가 없어야합니다. – l0gg3r