In my UI Tests, I want to call a remote endpoint to reset db status prior to running my UI Tests. This works great, but I want to make sure I'm catching any errors if the request fails. What I want to do is:
Here's some sample code that illustrates my point:
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 is part of the test run, as is tearDown. Use regular XCTest assertions in either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With