XCTWaiter.Result 不显示 XCTAssertEqual 打印每个结果时的情况
XCTWaiter.Result does not reveal which case each result is when printed by XCTAssertEqual
我正在使用XCTWaiter
来等待一个期望,然后我通过断言等待的结果是.completed
来断言期望已经实现,像这样:
let result = XCTWaiter.wait(for: [expectation], timeout: 5)
XCTAssertEqual(result, .completed)
在功能上,这工作正常,但是如果断言失败,错误消息毫无帮助地没有告诉我结果是哪种情况。
XCTAssertEqual failed: ("XCTWaiterResult") is not equal to ("XCTWaiterResult")
这样调试不方便。如何获取断言失败消息以报告 XCTWaiter.Result
的情况?
使XCTWaiter.Result
符合CustomDebugStringConvertible
。通过实现 debugDescription
属性,您可以在构建错误消息时提供 XCTWaiter.Result
的字符串解释。
extension XCTWaiter.Result: CustomDebugStringConvertible {
public var debugDescription: String {
switch self {
case .completed:
return "Completed"
case .incorrectOrder:
return "Incorrect Order"
case .interrupted:
return "Interrupted"
case .invertedFulfillment:
return "Inverted Fulfillment"
case .timedOut:
return "Timed Out"
@unknown default:
fatalError("Unknown XCTWaiter.Result case")
}
}
}
XCTAssertEqual failed: ("Timed Out") is not equal to ("Completed")
我正在使用XCTWaiter
来等待一个期望,然后我通过断言等待的结果是.completed
来断言期望已经实现,像这样:
let result = XCTWaiter.wait(for: [expectation], timeout: 5)
XCTAssertEqual(result, .completed)
在功能上,这工作正常,但是如果断言失败,错误消息毫无帮助地没有告诉我结果是哪种情况。
XCTAssertEqual failed: ("XCTWaiterResult") is not equal to ("XCTWaiterResult")
这样调试不方便。如何获取断言失败消息以报告 XCTWaiter.Result
的情况?
使XCTWaiter.Result
符合CustomDebugStringConvertible
。通过实现 debugDescription
属性,您可以在构建错误消息时提供 XCTWaiter.Result
的字符串解释。
extension XCTWaiter.Result: CustomDebugStringConvertible {
public var debugDescription: String {
switch self {
case .completed:
return "Completed"
case .incorrectOrder:
return "Incorrect Order"
case .interrupted:
return "Interrupted"
case .invertedFulfillment:
return "Inverted Fulfillment"
case .timedOut:
return "Timed Out"
@unknown default:
fatalError("Unknown XCTWaiter.Result case")
}
}
}
XCTAssertEqual failed: ("Timed Out") is not equal to ("Completed")