一入iOS海iOS Developer自动化与单元测试

iOS如何测试没有回调方法的异步函数

2017-03-02  本文已影响23人  韧卓

objc
DataSource *dataSource = [[DataSource alloc] init];
[dataSource loadData];
XCTestExpectation *expectation = [self expectationWithDescription:@"Dummy expectation"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
XCTAssert(dataSource.dataArray.count > 0, @"Data source has populated array after initializing and, you know, giving it some time to breath, man.");
[expectation fulfill];
});
[self waitForExpectationsWithTimeout:20.0 handler:nil];
objc

上一篇下一篇

猜你喜欢

热点阅读