var session = NSURLSession.sharedSession()
session.dataTaskWithRequest(urlRequest,
completionHandler: {(data: NSData!,
This is a fairly unique case, but if you're using a URLSession inside a unit test, you'll need to setup the expectations. Otherwise, your test case will end and it will appear that your request is never returning. Swift 3.0.1.
let expect = expectation(description: "dataTaskWithRequest - completes")
if let url = URL(string: "https://www.google.com/") {
let request = URLRequest(url: url)
URLSession.shared.dataTask(with: request) { ( data, response, error) in
print(data.debugDescription)
print(response.debugDescription)
print(error.debugDescription)
expect.fulfill()
}.resume()
waitForExpectations(timeout: 10, handler: nil)
}