所以Apple在Xcode 6的release note中说我们现在可以直接用XCTest做异步测试了。
有谁知道如何使用 Xcode 6 Beta 3(使用 objective-C 或 Swift)做到这一点?我不想要已知的信号量方法,而是新的 Apple 方式。
我搜索了已发布的笔记等,但一无所获。 XCTest header 也不是很明确。
最佳答案
Obj-C 示例:
- (void)testAsyncMethod
{
//Expectation
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method Works!"];
[MyClass asyncMethodWithCompletionBlock:^(NSError *error, NSHTTPURLResponse *httpResponse, NSData *data) {
if(error)
{
NSLog(@"error is: %@", error);
}else{
NSInteger statusCode = [httpResponse statusCode];
XCTAssertEqual(statusCode, 200);
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
if(error)
{
XCTFail(@"Expectation Failed with error: %@", error);
}
}];
}
关于ios - Xcode 6 中的 XCTest 和异步测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24704338/