swift - XCTestExpectation 应该如何初始化?
问题描述
有 2 个选项如何初始化XCTestExpectation
。首先,使用直接初始化程序。
import XCTest
class MyTests: XCTestCase {
let expectation = XCTestExpectation(description: "foo")`
}
第二个使用XCTest
实例方法。
import XCTest
class MyTests: XCTestCase {
let expectation = self.expectation(description: "foo")
}
两种方法产生相同的结果,所以我想知道哪个更好用?直接XCTestExpectation
初始化器会快一点吗?
解决方案
最大的区别是你想不想用waitForExpectations(timeout: TimeInterval, handler: XCWaitCompletionHandler)
。
waitForExpectations(timeout: TimeInterval, handler: XCWaitCompletionHandler)
只能在使用 . 创建期望时使用self.expectation(description: "foo")
。
否则,您需要调用wait(for expectations: [XCTestExpectation], timeout seconds: TimeInterval)
推荐阅读
- python - 从命令提示符访问 sastrawi 文件夹
- java - 如何避免多个 Switch case 语句
- javascript - 如何使用 auth().createUserWithEmailAndPassword 接收用户名和国家/地区
- javascript - 我无法从服务器获得响应
- autodesk-forge - 未从 Autodesk Forge API 收到 Webhook 事件
- uipath-robot - 协调器中的 Uipath 机器人调度
- html - 如何将页面导航到不同语言的 ID?
- android - Mapbox 反向地理编码并不总是返回结果
- java - 如何在java中输入并打印整个字符串?
- c++ - 如何将 GDI 位图转换为 GDI+ 位图、DrawImage?