Skip to content

Instantly share code, notes, and snippets.

@omidgolparvar
Created September 26, 2025 14:20
Show Gist options
  • Select an option

  • Save omidgolparvar/0caa2340bf5afa60714e7e24852671e7 to your computer and use it in GitHub Desktop.

Select an option

Save omidgolparvar/0caa2340bf5afa60714e7e24852671e7 to your computer and use it in GitHub Desktop.
Custom AppDelegate for Tests
/// https://www.linkedin.com/posts/jacobmartinbartlett_advanced-ios-testing-speed-up-your-tests-activity-7375121681171849216-2gSg
import UIKit
private func isRunningUnitTests() -> Bool {
NSClassFromString("Testing.Test") != nil ||
ProcessInfo.processInfo.environment["XCTestBundlePath"] != nil
}
let appDelegateClass: AnyClass = if isRunningUnitTests() {
UnitTestAppDelegate.self
} else {
AppDelegate.self
}
UIApplicationMain(
CommandLine.argc,
CommandLine.unsafeArgv,
nil,
NSStringFromClass(appDelegateClass)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment