I have the following test case code:
- (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");
}
I was expecting the test case to block and wait for the http request to finish.
The strange thing is that the AFHTTPRequestOperation never reaches the success block even the url is a valid one.
If I use the following code outside XCTest, it won't happen, the success block will be executed.
Has anyone has seen this before?