Skip to content

Instantly share code, notes, and snippets.

This file has been truncated, but you can view the full file.
09:37:30.652 xcodebuild[30138:9324129] Beginning test session XYZUITests-A4F643B9-4E10-47CD-B0AB-A99724E96BAB at 2018-05-11 09:37:30.650 with Xcode 9E145 on target <DVTiPhoneSimulator: 0x7fd5f30a3b80> {
SimDevice: iPhone 8 (85133256-457F-4F65-BCE2-B720B287B717, iOS 11.3, Booted)
} (11.3 (15E217))
09:37:30.653 xcodebuild[30138:9324129] /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
-workspace
./XYZ.xcworkspace
-scheme
Smoke Tests
-destination
platform=iOS Simulator,id=85133256-457F-4F65-BCE2-B720B287B717
let httpDispatcher = HTTPDispatcher()
let anyDispatcher = AnyDispatcher(httpDispatcher)
let taskReal = GetMoviesTask(dispatcher: AnyDispatcher(HTTPDispatcher()))
let taskTest = GetMoviesTask(dispatcher: AnyDispatcher(TestHTTPDispatcher()))
struct GetMoviesTask {
let dispatcher: AnyDispatcher<URLRequest, Data>
func load(success: ([Movie]) -> Void, failure: (Error) -> Void) {
let request = URLRequest(url: URL(string: “www.mydomain.com/movies")!)
  dispatcher.execute(request: request, success: { (data) in
  let movies = // (…)
  success(movies)
  }, failure: { error in
// (…)
let anyDispatcher = AnyDispatcher<URLSession, Data>
struct AnyDispatcher<R, O>: Dispatcher {
private let _execute: (R, (O) -> Void, (Error) -> Void) -> Void
init<D: Dispatcher>(_ dispatcher: D) where R == D.Request, O == D.Output {
_execute = dispatcher.execute
}
func execute(request: R, success: (O) -> Void, failure: (Error) -> Void) {
  _execute(request, success, failure)
}
let dispatcher: Dispatcher<URLRequest, Data>
struct GetMoviesTask {
let dispatcher: Dispatcher
func load(success: ([Movie]) -> Void, failure: (Error) -> Void) {
let request = URLRequest(url: URL(string: “www.mydomain.com/movies")!)
dispatcher.execute(request: request, success: { data in
// (…)
}, failure: { error in
// (…)
})
let task1 = GetMoviesTask(dispatcher: HTTPDispatcher())
let task2 = GetMoviesTask(dispatcher: TestHTTPDispatcher())
struct HTTPDispatcher: Dispatcher {
 func execute(request: URLRequest, success: (Data) -> Void, failure: (Error) -> Void) {
  // executes HTTP requests using URLSession
  // …
  }
}
struct TestHTTPDispatcher: Dispatcher {
  func execute(request: URLRequest, success: (Data) -> Void, failure: (Error) -> Void) {
 // to be used for unit tests, returns mocked data