在以下情况下,我面临一些警告问题:
let expect = expectation(description: "Async network call")
SomeManager.executeCall { result in
do {
/// 1.
XCTAssertThrowsError(try CoreManager.method())
expect.fulfill()
} catch {}
}
waitForExpectations(timeout: 15.0, handler: nil)
在1.编译器给出了一个错误
如果我删除do-catch,则会出现错误,即:
最佳答案
对XCTAssertThrowsError
的调用可消除该错误,因此您不需要执行/捕获操作。
对我来说似乎是个虫子。
作为一种解决方法,尝试像这样包装检查功能
func mustThrow() {
XCTAssertThrowsError(try CoreManager.method())
}
然后打电话
SomeManager.executeCall { result in
/// 1.
mustThrow()
expect.fulfill()
}
您可以在测试中本地定义函数,以避免污染文件中的名称。
关于ios - 单元测试错误抛出一个块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45099049/