Swift XctestExpection应该如何初始化?
有两个选项可以用来初始化Swift XctestExpection应该如何初始化?,swift,xctest,Swift,Xctest,有两个选项可以用来初始化xtestexpection。首先,使用直接初始值设定项 import XCTest class MyTests: XCTestCase { let expectation = XCTestExpectation(description: "foo")` } 然后使用XCTest实例方法 import XCTest class MyTests: XCTestCase { let expectation = self.expectation(descr
xtestexpection
。首先,使用直接初始值设定项
import XCTest
class MyTests: XCTestCase {
let expectation = XCTestExpectation(description: "foo")`
}
然后使用XCTest
实例方法
import XCTest
class MyTests: XCTestCase {
let expectation = self.expectation(description: "foo")
}
两种方法产生相同的结果,所以我想知道哪种方法更好?直接
xTestExpection
初始值设定项快一点吗?最大的区别在于是否要使用WaitForExpections(超时:时间间隔,处理程序:xWaitCompletionHandler)
WaitForExpections(超时:时间间隔,处理程序:XCWaitCompletionHandler)
只能在使用self.expectation(description:“foo”)
创建期望时使用
否则,您需要调用
wait(期望值:[xTestExpection],超时秒数:TimeInterval)
最大的区别在于您是否要使用WaitForExpections(超时:TimeInterval,处理程序:xWaitCompletionHandler)
WaitForExpections(超时:时间间隔,处理程序:XCWaitCompletionHandler)
只能在使用self.expectation(description:“foo”)
创建期望时使用
否则,您需要调用wait(期望值:[xctestexpection],超时秒数:TimeInterval)