Last active
March 26, 2018 13:53
-
-
Save chrisleversuch/36e1f2b9c3c18eb198395e239dfd47bf to your computer and use it in GitHub Desktop.
Pointers for UI testing in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
if NSClassFromString("XCTestCase") != nil { | |
return true | |
} | |
// Setup Code 1 - Do any setup that is needed for both the app and UI tests e.g. global styling | |
if ProcessInfo.processInfo.arguments.contains("UITestingEnabled") { | |
if let launchViewController = ProcessInfo.processInfo.environment["launchViewController"], | |
let screen = LaunchScreen(rawValue: launchViewController) { | |
let viewController = self.viewController(for: screen) | |
setupWindow(rootViewController: UINavigationController(rootViewController: viewController)) | |
} else { | |
// Default state if we've forgotten to pass a launchViewController or it's not a valid LaunchScreen | |
setupWindow(rootViewController: UIViewController()) | |
} | |
return true | |
} | |
// Setup Code 2 - Do any setup that is only needed by the app | |
return true | |
} | |
enum LaunchScreen: String { | |
case productList | |
case productDetail | |
case basket | |
case payment | |
case confirmation | |
} | |
private func viewController(for screen: LaunchScreen) -> UIViewController { | |
switch screen { | |
case .productList: | |
return viewControllerForProductList() | |
case .productDetail: | |
return viewControllerForProductDetail() | |
case .basket: | |
return viewControllerForBasket() | |
case .payment: | |
return viewControllerForPayment() | |
case .confirmation: | |
return viewControllerForConfirmation() | |
} | |
} | |
private func viewControllerForXXX() -> UIViewController { | |
// return a subclass of UIViewController | |
} | |
private func setupWindow(rootViewController: UIViewController) { | |
self.window = UIWindow(frame: UIScreen.main.bounds) | |
self.window?.rootViewController = rootViewController | |
self.window?.makeKeyAndVisible() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment