Don't launch simulator when running unittests

前端 未结 6 1431
悲哀的现实
悲哀的现实 2020-12-07 17:44

Some background:

I have iOS application with a target configured to run unitTests. And I am running build automation tool jenkins on my MacBook whic

6条回答
  •  温柔的废话
    2020-12-07 18:07

    I've asked the same question to apple engineers. Unfortunately it doesn't seem you can accomplish this and stay with iOS at the same time. There are some tricks you can do to check if testing. You could put this code snippet in your AppDelegate.h or some other global class to say not load a root viewcontroller and prevent any wierdo ui stuff from corrupting your unit tests:

    static BOOL isTesting() {
        BOOL isTesting = !isEmpty([[[NSProcessInfo processInfo] environment] objectForKey:@"XCInjectBundle"]);
        return isTesting;
    }
    

    I've also had an apple engineer verify this is a legitimate check. And to give credit where credit is due, this is from: Programmatically determine current target (run or test) in iOS project

    EDIT: I've also had success with this and it's a little more straight forward:

    static BOOL isTesting() {
        return [[[NSProcessInfo processInfo] processName] isEqualToString:@"xctest"];
    }
    

提交回复
热议问题