---
title: XCUITest Environment Variables
description: Pass environment variables and launch arguments to your XCUITest test
  runner and to the app under test. Covers testEnv, testArgs, appEnv and appArgs.
source_url:
  html: https://testingbot.com/support/app-automate/xcuitest/environment-variables
  md: https://testingbot.com/support/app-automate/xcuitest/environment-variables.md
---

# Environment variables and launch arguments

You can pass environment variables and launch arguments with an XCUITest run, without rebuilding your test bundle. Use this to point a suite at a staging backend, switch on a test mode in your app, or pass any other run-specific setting.

There are two targets:

- [testEnv and testArgs](https://testingbot.com#test): for the process that runs your test code
- [appEnv and appArgs](https://testingbot.com#app): for your app, when a test launches it

## Test runner: testEnv and testArgs

`testEnv` sets environment variables and `testArgs` adds launch arguments for the process that runs your test code. Read them in your tests with `ProcessInfo.processInfo.environment` and `ProcessInfo.processInfo.arguments`.

[CLI](https://testingbot.com#) [cURL](https://testingbot.com#)

```bash
testingbot xcuitest app.ipa app-test.zip \
  --device "iPhone.*" \
  --real-device \
  --test-env API_URL=https://staging.example.com \
  --test-env RETRIES=2 \
  --test-arg=-verbose
```

```bash
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/xcuitest/:id/run" \
-d '{ "options": { "testEnv": { "API_URL": "https://staging.example.com", "RETRIES": "2" }, "testArgs": ["-verbose"] }, "capabilities":[{"deviceName":"iPhone.*", "platformName":"iOS", "realDevice": true}]}' \
-H "Content-Type: application/json"
```

```swift
let apiURL = ProcessInfo.processInfo.environment["API_URL"]
let verbose = ProcessInfo.processInfo.arguments.contains("-verbose")
```

## App under test: appEnv and appArgs

`appEnv` sets environment variables and `appArgs` adds launch arguments for your app when a test starts it with `XCUIApplication().launch()`. Your app reads them with `ProcessInfo.processInfo.environment` and `ProcessInfo.processInfo.arguments`, the same way it would read `launchEnvironment` and `launchArguments` set in the test code.

[CLI](https://testingbot.com#) [cURL](https://testingbot.com#)

```bash
testingbot xcuitest app.ipa app-test.zip \
  --device "iPhone.*" \
  --real-device \
  --app-env FEATURE_NEW_CHECKOUT=on \
  --app-arg=-UITestMode
```

```bash
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/xcuitest/:id/run" \
-d '{ "options": { "appEnv": { "FEATURE_NEW_CHECKOUT": "on" }, "appArgs": ["-UITestMode"] }, "capabilities":[{"deviceName":"iPhone.*", "platformName":"iOS", "realDevice": true}]}' \
-H "Content-Type: application/json"
```

## Rules and limits

- `testEnv` and `appEnv` are JSON objects. Names start with a letter or underscore and contain only letters, digits and underscores. Values are strings; numbers and booleans are converted to strings.
- `testArgs` and `appArgs` are JSON arrays of strings.
- With the CLI, write an argument that starts with a dash with an equals sign, for example `--test-arg=-verbose`, so it is not read as a CLI option.
- Up to 100 variables per object and 100 arguments per list; each value can be up to 4096 characters.
- Options that break these rules make the API answer with a `400` error.
- Do not pass passwords or access tokens in these options.

You can combine these options with [test filters](https://testingbot.com/support/app-automate/xcuitest/filter) and the other XCUITest options in the same `options` object.

## Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
