在我的UI测试中,我想在运行UI测试之前调用远程端点来重置db状态。这很好用,但我想确保在请求失败时我发现任何错误。我想做的是:
以下是一些示例代码,说明了我的观点:
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()
}
答案 0 :(得分:3)
setUp
是测试运行的一部分,tearDown
也是如此。在任一个中使用常规XCTest断言。