• performs its functions within an acceptable time, • is sufficiently usable, • can be installed and run in its intended environments, and • achieves the general result its stakeholders desire. (來來源: Wikipedia)
"Status code: 200") // when XCTAssertEqual(controllerUnderTest?.searchResults.count, 0, "searchResults should be empty before the data task runs") let url = URL(string: "https://itunes.apple.com/search?media=music&entity=song&term=abba") let dataTask = controllerUnderTest?.defaultSession.dataTask(with: url!) { data, response, error in if let error = error { print(error.localizedDescription) } else if let httpResponse = response as? HTTPURLResponse { if httpResponse.statusCode == 200 { promise.fulfill() self.controllerUnderTest?.updateSearchResults(data) } } } dataTask?.resume() waitForExpectations(timeout: 5, handler: nil) // then XCTAssertEqual(controllerUnderTest?.searchResults.count, 3, "Didn't parse 3 items from fake response") }
Testability https://youtu.be/acjvKJiOvXw • Dependency Injection in Swift https://youtu.be/-n8allUvhw8 • Dependency Injection (DI) in Swift http://ilya.puchka.me/dependency-injection-in-swift/