如何在xCode 6中使用expectations建立异步单元测试?

5

当我想在xCode 6中为我的异步单元测试注册期望值时,我应该使用什么语法?目前在谷歌上没有相关的易于搜索的内容,而出现的内容都是用Swift编写的。我正在寻找Objective-C的示例。

1个回答

6

我找到了一篇关于it技术的不错博客文章,作者是Sean McCune: 使用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);
        }
    }];
}

我建议阅读他的文章以获取更详细的解释。

哇!XCTExpectations 真是太棒了 :) - pgpb.padilla

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接