Skip to content

Instantly share code, notes, and snippets.

@darsen
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darsen/0288cfa117de23fbb2d0 to your computer and use it in GitHub Desktop.
Save darsen/0288cfa117de23fbb2d0 to your computer and use it in GitHub Desktop.
import XCTest
class AsyncTests: XCTestCase {
func testExample() {
//set expectaton
let expectation = expectationWithDescription("Swift Expectations")
let url = NSURL(string: "http://www.stackoverflow.com")
let request = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
(response, data, error) in
let page = NSString(data: data!, encoding: NSUTF8StringEncoding)
XCTAssertTrue(page!.containsString(">Stack Overflow<"))
//fulfill expectation
expectation.fulfill()
}
//wait
waitForExpectationsWithTimeout(5.0, handler:nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment