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 from UI Testing and there aren't any obvious parameters to differentiate between the app running normally vs in UI Testing. Is there a way to find out?
Two workarounds that I'm not satisfied with are:
- Set
XCUIApplication.launchEnvironment
with some variable that I later check in the app. This isn't good because you have to set it in thesetUp
method of each test file. I tried setting the environment variable from the scheme settings but that doesn't propagate to the app itself when running UI Testing tests. - Check for the lack of existence of the environment variable
__XPC_DYLD_LIBRARY_PATH
. This seems very hacky and might only be working now because of a coincidence in how we have our target build settings set up.