Skip to content

Instantly share code, notes, and snippets.

@netbe
Created June 5, 2015 16:27
Show Gist options
  • Save netbe/991191be55a1ef11c2d7 to your computer and use it in GitHub Desktop.
Save netbe/991191be55a1ef11c2d7 to your computer and use it in GitHub Desktop.
AppDelegate UnitTests Swift
// AppDelegate.swift
import UIKit
func isRunningTests() -> Bool {
let environment = NSProcessInfo.processInfo().environment
if let injectBundle = environment["XCInjectBundle"] as? NSString {
return injectBundle.pathExtension == "xctest"
}
return false
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
override init() {
super.init()
if (isRunningTests()){
// This bundle has unit tests injected. Let's not really start the app to avoid interfering with the tests.
let infoDictionary:NSDictionary = NSBundle.mainBundle().infoDictionary!
infoDictionary.setValue("UnitTests", forKey:"UIMainStoryboardFile")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment