Unit Testing in Xcode, does it run the app?

后端 未结 10 988
陌清茗
陌清茗 2020-11-29 21:54

I\'m running into a strange problem that I haven\'t run into before.

When you do cmd+U to run your Unit Tests (OCUnit for example) does it actually call the main.m,

10条回答
  •  被撕碎了的回忆
    2020-11-29 21:59

    In Swift, I prefere to bypass a normal execution path inside application: didFinishLaunchingWithOptions:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        guard normalExecutionPath() else {
            window = nil
            return false
        }
    
        // regular setup
    
        return true
    }
    
    private func normalExecutionPath() -> Bool {
        return NSClassFromString("XCTestCase") == nil
    }
    

    Code inside guard will remove any views created from storyboard.

提交回复
热议问题