【问题标题】:XCTestExpectation just hangsXCTestExpectation 只是挂起
【发布时间】:2020-07-18 16:34:59
【问题描述】:

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

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

而且它不会失败。它只是挂起。有谁知道为什么会发生这种情况?

【问题讨论】:

  • 你试过用XCTestExpectation(description:)代替expectation(description:)吗?我怀疑问题可能是您将expec 添加到self.expectations,为此您应该等待waitForExpectations 而不是wait(for:)
  • @DávidPásztor 你的建议奏效了!我一直认为它们是可以互换的。无论如何,请随时将其粘贴为答案,我会接受

标签: ios swift xctest xctestcase xctestexpectation


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 2016-08-06
    • 2016-05-19
    相关资源
    最近更新 更多