# How-to: run tests from the CLI

> Run a Test Manager test set from UiPath CLI as part of a CI pipeline and correctly interpret the execution verdict.

This page shows how to run a UiPath **Test Manager** test set from the CLI as part of a CI pipeline — and, just as importantly, how to read the verdict correctly. The [`uip tm`](./uip-test-manager.md) tool splits a test set run into three verbs; the launch verb alone exits `0` even when tests fail.

## The golden rule: launch → wait → verify

`uip tm testsets run` on its own does not exit non-zero *because tests failed*. Getting a pipeline to fail on a red test set run takes the wait step, and the verify step gives the details (a package run takes one command, see [Run every test in a local project or an uploaded package](#run-every-test-in-a-local-project-or-an-uploaded-package)):

1. **Launch** — [`uip tm testsets run`](./uip-test-manager-testsets.md#uip-tm-testsets-run). Queues the run and exits `0` as soon as Orchestrator accepts the request. `Status: "Running"` in the response reflects the state **at launch**, not the final outcome.
2. **Block** — [`uip tm wait`](./uip-test-manager-wait.md). Polls until the execution reaches a terminal state (`Finished` or `Cancelled`). Exits `0` when the execution finished with no failed test, **`1`** when a test failed or the run was cancelled, and **`4`** on `--timeout`. Tests with no result do not fail the wait.
3. **Verify** — [`uip tm report get`](./uip-test-manager-report.md). Reads `Data.Failed` (and `Passed`, `None`, `PassRate`) and the failed test cases. Exits `0` whenever it successfully fetches the summary, regardless of pass/fail.

A launch+wait shortcut exists for test sets — [`uip tm testsets run --wait`](./uip-test-manager-testsets.md#uip-tm-testsets-run) launches and blocks in one call (`--timeout`/`--poll-interval` tune the poll) and uses the same exit codes as `wait`: `1` when a test failed or the run was cancelled, `4` on timeout. Use the verify step to print which test cases failed, or to fail the build on tests with no result.

## Run every test in a local project or an uploaded package

When the tests are in a local RPA test project, or ship in a package already uploaded to Orchestrator, [`uip tm run --type package`](./uip-test-manager-run.md) launches, waits, and verifies in one call. With `--project-path`, it also packs and uploads the project first. It runs every test case in the package, with no test set to author, writes a JUnit or UiPath report to `--result-path`, and exits `1` when a test fails or reports no result, no test runs, or the run is cancelled, so the pipeline fails on a red run without a separate verify step.

```bash
# a package already uploaded to Orchestrator
uip tm run --type package \
  --project-key DEMO \
  --package-name MyTests \
  --package-version 1.0 \
  --folder-path Shared \
  --result-path ./results/junit.xml

# a local RPA test project: pack, upload, and run
uip tm run --type package \
  --project-key DEMO \
  --project-path ./MyTests/project.json \
  --folder-path Shared \
  --result-path ./results/junit.xml
```

As soon as the execution starts, the command prints `Execution started: <link>` on stderr, so the CI log links to the run in Test Manager while the tests are still running.

Leave out `--project-key` to run the package in the tenant default project; `Data.ProjectKey` in the output names the project the tests ran in.

| Exit code | Meaning |
|---|---|
| `0` | Every test passed. |
| `1` | A test failed or reported no result, the run was cancelled, no test ran, or a service call failed. A missing login or no access to a project you passed also exits `1`, before the run starts. |
| `2` | Login or permission problem after the run starts, or no permission to open or create the tenant default project. |
| `3` | Bad option or input. |
| `4` | The run exceeded `--timeout`. |

## Minimum viable snippet

```bash
#!/usr/bin/env bash
set -euo pipefail

# 1. Launch
EXECUTION_ID=$(uip tm testsets run \
  --test-set-key DEMO:10 \
  --output-filter "ExecutionId" \
  --output plain)

# 2. Block (default timeout: 30 min; adjust with --timeout)
code=0
uip tm wait \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO \
  --timeout 1800 || code=$?

if [ "$code" -eq 4 ]; then
  echo "test run did not finish within 30 minutes" >&2
  exit 4
fi

# 3. Verify
FAILED=$(uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO \
  --output-filter "Failed" \
  --output plain)

if [ "$FAILED" -gt 0 ]; then
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

if [ "$code" -ne 0 ]; then
  echo "wait failed or the run was cancelled (exit $code)" >&2
  exit "$code"
fi

echo "all tests passed"
```

`--output plain` returns the bare value for a scalar filter result; this is the safest way to capture a field into a shell variable without parsing JSON. See [Scripting patterns — reading values out of the envelope](./scripting-patterns.md#reading-values-out-of-the-envelope).

## Picking inputs to the commands

`uip tm testsets run` needs the **test set key**, not its UUID. The key has the form `<ProjectKey>:<Number>` — for example, `DEMO:10`. Two ways to find it:

```bash
# From the Test Manager UI — it is the "Key" column in the test set list.

# Or from the CLI:
uip tm testsets list --project-key DEMO --filter smoke \
  --output-filter "[*].{key:TestSetKey, name:Name}"
```

`list` takes the project as `--project-key` or `--project-id`. `run` derives the project from the test set key's prefix (`DEMO:10` → project `DEMO`).

If you need the numeric UUID for `uip tm executions list --test-set-id`, that is the `Id` field on the same list output — **not** the `TestSetKey`.

## Picking which cases run

[`uip tm testsets run --execution-type`](./uip-test-manager-testsets.md#uip-tm-testsets-run) controls which test cases inside the set run:

- `automated` *(default)* — only automated test cases.
- `manual` — only manual test cases.

Any other value is refused with exit code `3`.

For CI, keep the default (`automated`) — manual cases require a human to mark pass/fail and will sit in `InProgress` until `--timeout`.

## Passing parameter overrides

If the test set exposes parameters (for example, a target URL or an account ID), override them at launch with `--input-path`:

```bash
cat > ./params.json <<'EOF'
[
  {"name": "TargetUrl", "type": "String", "value": "https://staging.example.com"},
  {"name": "AccountId", "type": "String", "value": "acme-staging"}
]
EOF

uip tm testsets run --test-set-key DEMO:10 --input-path ./params.json
```

Overrides are matched against the test set's current parameter definitions by `name` (case-insensitive) and, when present, `type`. If the server reports no parameter definitions, the inputs are sent as-is. The overrides are saved on the test set, so later runs without `--input-path` reuse them.

## Reading the verdict in detail

[`uip tm report get`](./uip-test-manager-report.md) is the summary reader. Default output gives you the scorecard; pass `--query` (a jq-style filter) to extract a subset in one call:

```bash
# Pretty scorecard
uip tm report get --execution-id "$EXECUTION_ID" --project-key DEMO

# Script-friendly — JSON with just the counts
uip tm report get --execution-id "$EXECUTION_ID" --project-key DEMO \
  --query '{total: .TotalTests, passed: .Passed, failed: .Failed}'
```

The `Data` envelope has these fields (full schema in the [`report get` reference](./uip-test-manager-report.md)):

- `TotalTests`, `Passed`, `Failed`, `None` (tests with no result), `PassRate` (a number such as `80`, computed over the tests that passed or failed), `Duration` (`HH:MM:SS`).
- `FailedTests` — one entry per failed test case, with `TestCaseName` and an `Error` string (either the log's `info` field, or a concatenated list of failed assertion messages).

When you need a JUnit-XML file that your CI's test dashboard can ingest, use [`uip tm result download`](./uip-test-manager-result.md) instead of (or alongside) `report get`.

## Surfacing failed cases in CI logs

Turn the `FailedTests` array into a human-readable line per failure before exiting the pipeline:

```bash
if [ "$FAILED" -gt 0 ]; then
  uip tm report get \
    --execution-id "$EXECUTION_ID" \
    --project-key DEMO \
    --output-filter "FailedTests[*].[TestCaseName, Error]" \
    --output plain >&2
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi
```

For deeper failure analysis — assertion-by-assertion detail on a single failed case — use [`uip tm testcaselog list-assertions`](./uip-test-manager-testcaselog.md#uip-tm-testcaselog-list-assertions) on the log IDs returned by [`uip tm executions testcaselogs list --only-failed`](./uip-test-manager-executions.md#uip-tm-executions-testcaselogs-list).

## Retrying flaky cases

If a run has failures that might be flaky (timing, environment), retry **only the failed cases** in place:

```bash
uip tm executions retry \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO
```

[`uip tm executions retry`](./uip-test-manager-executions.md#uip-tm-executions-retry) reuses the same execution ID — no new one is created. If there are no failures to retry, it prints an informational message and exits `0` (intentionally not an error).

After `retry`, loop back through `wait` + `report get` on the same execution ID. For a package run, `uip tm run --max-retries <count>` re-runs failed test cases within the same command.

## Common pitfalls

- **Parsing `testsets run` output to decide pass/fail.** The `Status` field at launch is typically `Running` — it means the run was queued, not that every test passed. Always call `wait`, or pass `--wait`, and read the exit code.
- **Forgetting the `--timeout` on `wait`.** Default is 1800 seconds (30 minutes). Pass `0` to wait indefinitely (rarely what you want in CI); pass a larger number for long suites.
- **Treating exit `1` from `wait` as an infrastructure failure only.** `wait` exits `1` when a test failed or the run was cancelled, as well as when polling fails; `Code` in the envelope is `ExecutionTestsFailed` or `ExecutionCancelled` for the first two. A timeout exits `4` — see [`uip tm wait` exit codes](./uip-test-manager-wait.md#exit-codes).
- **Using `testsets` verbs to create tests.** Test cases and their links to Orchestrator automations come from [`uip tm testcases`](./uip-test-manager-testcases.md); `testsets` only groups them.

## Full CI-ready example

A bash snippet for a pipeline step — fails the build when any test fails, times out, or errors:

```bash
#!/usr/bin/env bash
set -euo pipefail

TEST_SET_KEY="${TEST_SET_KEY:?TEST_SET_KEY is required}"
PROJECT_KEY="${PROJECT_KEY:?PROJECT_KEY is required}"
TIMEOUT="${TEST_TIMEOUT:-1800}"

EXECUTION_ID=$(uip tm testsets run \
  --test-set-key "$TEST_SET_KEY" \
  --output-filter "ExecutionId" \
  --output plain)

echo "started execution $EXECUTION_ID" >&2

code=0
uip tm wait \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY" \
  --timeout "$TIMEOUT" || code=$?

if [ "$code" -eq 4 ]; then
  echo "execution $EXECUTION_ID did not finish within ${TIMEOUT}s" >&2
  exit 4
fi

# Get the scorecard and the names of any failed cases in one shot
uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY"

FAILED=$(uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY" \
  --output-filter "Failed" \
  --output plain)

if [ "$FAILED" -gt 0 ]; then
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

if [ "$code" -ne 0 ]; then
  echo "wait failed or the run was cancelled (exit $code)" >&2
  exit "$code"
fi

echo "all tests passed"
```

Run this script after your Solution deploy step in any of the [CI recipes](./recipes-azure-devops.md). The only env-specific config is `TEST_SET_KEY` / `PROJECT_KEY` — set them per environment in the pipeline, and the same script promotes cleanly across dev/stage/prod.

## See also

- [`uip tm` overview](./uip-test-manager.md) — the full command surface.
- [`uip tm testsets run`](./uip-test-manager-testsets.md#uip-tm-testsets-run), [`uip tm wait`](./uip-test-manager-wait.md), [`uip tm report get`](./uip-test-manager-report.md) — the three verbs used above.
- [`uip tm result download`](./uip-test-manager-result.md) — JUnit XML export for CI dashboards.
- [Scripting patterns](./scripting-patterns.md) — polling, JSON filtering, idempotent pipelines.
- [Exit codes](./exit-codes.md) — the shared contract.
