Testing in iOS, Episode 12: XCTestExpectation | raywenderlich.com

XCTestExpectation is a class that represents an expected outcome in an asynchronous test. Making use of its main features boils down to three lines of code.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/25842120-testing-in-ios/lessons/12

At 6.44, I don’t think there is a diff between:

URLSession.shared.dataTask(with: url) { data, response, error in
      XCTAssertNotNil(data)
      expection.fulfill()
    }.resume()

and


```swift
URLSession.shared.dataTask(with: url) { data, response, error in
      expection.fulfill()
      XCTAssertNotNil(data)
    }.resume()

data, response are nil and error is non-nil. Would be great if there can be a bit more details here. Thanks.

See the previous version of the course for a demonstration of how the results are nondeterministic. When I recorded that, the tests happened to pass.

Unfortunately, there’s no way to demonstrate this predictably. Just fulfill at the end, like I went over, and you won’t ever see related bugs.