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

前端 未结 7 1422
抹茶落季
抹茶落季 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:31

    I didn't succeed with setting a launch environment, but got it to work with launch arguments.

    In your tests setUp() function add:

    let app = XCUIApplication()
    app.launchArguments = ["testMode"]
    app.launch()
    

    In your production code add a check like:

    let testMode =  NSProcessInfo.processInfo().arguments.contains("testMode")
    if testMode {
      // Do stuff
    }
    

    Verified using Xcode 7.1.1.

    0 讨论(0)
提交回复
热议问题