在我的 UI 测试中,我想在运行 UI 测试之前调用远程端点来重置数据库状态。这很好用,但我想确保在请求失败时捕获任何错误。我想做的是:
- 停止运行后续测试(将其标记为失败)
- 提供一些发生情况的日志。
这里有一些示例代码来说明我的观点:
override func setUp() {
super.setUp()
var finished = false
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) {
let request = Alamofire.request(.GET, "http://xxx.xxx.xxx.xxx/resetdb")
request.response() {
request, response, data, error in
if let _ = error {
let message = "Could not call remote helper -- \(response?.statusCode)"
XCTFail(message) // doesn't work
debugPrint(message) // can't see this anywhere
}
finished = true
}
}
while !finished {
NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture())
}
app = XCUIApplication()
app.launch()
}
最佳答案
setUp
是测试运行的一部分,tearDown
也是如此。在任一中使用常规 XCTest 断言。
关于swift - 如何报告XCTest的setUp函数中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35583050/