我有一个
setUpWithError
函数,我想用它来防止每个测试设置中重复代码。
在运行一些同步函数之前,我想运行几个异步函数。
到目前为止,我有这个:
override func setUpWithError() throws {
let expectation = XCTestExpectation(description: "Setup")
Task {
await function1()
await function2()
expectation.fulfill()
}
wait(for: [expectation], timeout: defaultTimeout)
synchronousFunction()
}
在调用
synchronousFunction()
之前,任务中的期望似乎不会“等待”。
请问我该如何解决这个问题?非常感谢。