当我想在 xCode 6 中注册对我的异步单元测试的期望时,我应该使用什么语法?在 Google 上还没有任何内容可以轻松搜索到该主题,而且显示的内容都是用 Swift 编写的。我正在寻找 Objective-C 示例
最佳答案
我发现了 Sean McCune 的一篇关于它的不错的博客文章: Asynchronous Testing With Xcode 6 .
对于 Objective-C,他举了一个这样的例子:
- (void)testWebPageDownload
{
XCTestExpectation *expectation =
[self expectationWithDescription:@"High Expectations"];
[self.pageLoader requestUrl:@"http://bignerdranch.com"
completionHandler:^(NSString *page) {
NSLog(@"The web page is %ld bytes long.", page.length);
XCTAssert(page.length > 0);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
if (error) {
NSLog(@"Timeout Error: %@", error);
}
}];
}
我建议阅读他的帖子以获得进一步的解释。
关于objective-c - 如何使用 xCode 6 中的期望设置异步单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25165929/