XCTestExpectation只是挂起

问题描述 投票:0回答:1

我不知道发生了什么。我在测试中使用的是expectation,它不会超时。我已经删除了很多测试,现在只剩下:

func testItem() {
    let expec = expectation(description: "expection")
    wait(for: [expec], timeout: 3.0)
}

而且它不会失败。它只是挂了。有谁知道为什么会这样?

ios swift xctest xctestcase xctestexpectation
1个回答
0
投票

如果使用XCTestCase.expectation(description:),将返回的XCTestExpectation添加到self.expectations,则应使用waitForExpectations而不是wait(for:)

使用wait(for:)时,您应该使用XCTestExpectation(description:)来创建期望。

© www.soinside.com 2019 - 2024. All rights reserved.