ios - 在 IOS 中使用异步代码编写单元测试
问题描述
我需要测试我的 Api 调用响应但在块返回单元测试完成之前我如何测试我的 API
解决方案
你可以使用XCTestExpectation
它。
XCTestExpectation *apiCallExpectation = [self expectationWithDescription:@"APICall"];
[apiService apiCall:^(BOOL success) {
XCTAssert(success);
[apiCallExpectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:^(NSError *error) {
[apiCallExpectation closeWithCompletionHandler:nil];
}];
推荐阅读
- reactjs - react-native 使状态栏“barStyle”可动画化
- java - 当我包含 jax 依赖项 java 11 时,tomcat 9 没有启动
- haskell - 这个 Haskell Pandoc 过滤器是如何工作的?
- racket - # 时出现错误的语法错误
在一个列表中 - mysql - 为什么MYSQL中datetime字段的毫秒数有时显示为000?
- python - REST API, JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- css - 一组对齐的 CSS 按钮
- java - Jenkins - 如何使用 Groovy 获取方法的返回类型
- java - driver.get(URL)、driver.navigate().to(URL) 和 driver.navigate().back() 不工作
- sprite - x位置如何在精灵中工作