【发布时间】:2015-01-17 13:26:04
【问题描述】:
我有以下测试用例代码:
- (void)testExample {
// URL https://api.spotify.com/v1/search?q=album%3AJustified%20artist%3AJustin%20Timberlake&type=album
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
[[AFHTTPRequestOperationManager manager] GET:@"https://api.spotify.com/v1/search"
parameters:@{@"q":@"album:Justified artist:Justin Timberlake",
@"type":@"album"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
dispatch_semaphore_signal(sem);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}
];
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
}
我期待测试用例阻塞并等待 http 请求完成。
奇怪的是,即使 url 是有效的,AFHTTPRequestOperation 也永远不会到达成功块。
如果我在 XCTest 之外使用以下代码,则不会发生,将执行成功块。
有没有人见过这个?
【问题讨论】:
标签: objective-c ios8 afnetworking xctest