How to detect if iOS app is running in UI Testing mode

前端 未结 7 1438
抹茶落季
抹茶落季 2020-12-05 01:46

I would like my app to run special code (e.g. resetting its state) when running in UI Testing mode. I looked at environment variables that are set when the app is running fr

7条回答
  •  清歌不尽
    2020-12-05 02:29

    My solution is almost identical to that of Ciryon above, except that for my macOS Document-based app I had to prepend a hyphen to the argument name:

    let app = XCUIApplication()
    app.launchArguments.append("-Testing")
    app.launch() 
    

    ...otherwise, "Testing" ends up interpreted as the name of the document to open when launching the app, so I was getting an error alert:

提交回复
热议问题