Upgrade to Pro — share decks privately, control downloads, hide ads and more …

テスト実行時に 不要な初期化コードを実行しないようにする

kNagadou
February 22, 2018

テスト実行時に 不要な初期化コードを実行しないようにする

potatotips#48での発表スライドです

kNagadou

February 22, 2018
Tweet

More Decks by kNagadou

Other Decks in Programming

Transcript

  1. ᶅςετ༻ͷίʔυ͕"QQ%FMFHBUF಺ʹଘࡏͯ͠͠·͏ let isRunningTest = ProcessInfo.processInfo.environment["XCInjectBundleInto"] != nil if isRunningTest {

    // ςετ࣌ͷॳظԽॲཧ } else { // ϓϩμΫγϣϯ༻ͷॳظԽॲཧ }  ςετ༻ͷॳظԽॲཧ͸ผͷ৔ॴʹ෼͚͍ͨ 
  2. import UIKit let isRunningTest = ProcessInfo.processInfo.environment["XCInjectBundleInto"] != nil let appDelegateClass

    = isRunningTest ? NSStringFromClass(TestAppDelegate.self) : NSStringFromClass(AppDelegate.self) let args = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)) UIApplicationMain(CommandLine.argc, args, nil, appDelegateClass) <NBJOTXJGU> NBJOTXJGUΛϓϩδΣΫτʹ௥Ճɻ ςετ࣮ߦதͳΒɺ5FTU"QQ%FMFHBUFΛUIApplicationMain(_,_,_,_)ͷҾ਺ ʹ౉͢ॲཧΛॻ͘ɻ 
  3. <"QQ%FMFHBUFTXJGU> .BJO*OUFSGBDFΛϩʔυ͢ΔίʔυΛॻ͘  let storyboard = UIStoryboard(name: "Main", bundle: nil)

    window = UIWindow() window?.rootViewController = storyboard.instantiateInitialViewController() window?.makeKeyAndVisible()