> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xenoci.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test

> box test builds your app and runs its tests on a fresh simulator on a real Mac, then prints how many passed and each failing test with its message

> [!NOTE]
>
> **When to use it.**
>
> * Before you push, to know the tests pass on iOS
> * After your agent changed code, so it can see its own failing test and fix it

## Run the tests

```bash theme={"system"}
box test
```

<video controls muted loop playsInline autoPlay preload="metadata" poster="/media/docs/ios-test-poster.webp" src="https://mintcdn.com/xenoci/ZFKGlbE4Q2bw14Om/media/docs/ios-test.mp4?fit=max&auto=format&n=ZFKGlbE4Q2bw14Om&q=85&s=dbb46aa899ae5a0a072a1ccf147e266d" width="1280" height="778" />

box test running the Tally unit and UI tests on a fresh simulator

```text theme={"system"}
box: queue: job bj_NWidfRUrt0Hz0o0a (test, ios, $0.05/min) submitted
box: status: running
box: build: xcodebuild build-for-testing
** TEST BUILD SUCCEEDED **
box: build: done in 12s
box: test: running the tests on the simulator
** TEST EXECUTE SUCCEEDED **
box: status: succeeded
box: results: saved to ./.box/out/bj_NWidfRUrt0Hz0o0a/ (destinations.txt, test.log, test-summary.json, test.xcresult.zip)
box: tests 1 passed, 0 failed
box: bj_NWidfRUrt0Hz0o0a succeeded, 180s billed, $0.15
```

> [!NOTE]
>
> Job `bj_NWidfRUrt0Hz0o0a` on the production Mac: 180 s billed, \$0.15

## When a test fails

Here one test expects the counter to start at 1 while the app starts it at 0. box prints the count, then each failing test with the assertion message, and exits with 1

```text theme={"system"}
box: test: running the tests on the simulator
** TEST EXECUTE FAILED **
box: status: failed
box: results: saved to ./.box/out/bj_aDxtZUJUe0bpuoFx/ (destinations.txt, test.log, test-summary.json, test.xcresult.zip, why.txt)
box: tests 1 passed, 1 failed
  FAIL BoxDemoTests/testCountStartsAtOne(): XCTAssertEqual failed: ("0") is not equal to ("1") - the counter should start at 1
box: bj_aDxtZUJUe0bpuoFx failed, 180s billed, $0.15
box: why: FAIL BoxDemoTests/testCountStartsAtOne(): XCTAssertEqual failed: ("0") is not equal to ("1") - the counter should start at 1
box: details: .box/out/bj_aDxtZUJUe0bpuoFx/why.txt
```

> [!NOTE]
>
> Job `bj_aDxtZUJUe0bpuoFx` on the production Mac: 180 s billed, \$0.15

The file and line of the failure are in `why.txt`; see [Why it failed](https://docs.xenoci.com/ios/why.md). `test-summary.json` holds the same counts for a script, and `test.xcresult.zip` opens in Xcode

## Tests and a picture in one job

`--screenshot` launches the app after the tests in the same job and saves what the simulator showed

```bash theme={"system"}
box test --screenshot out.png
```

```text theme={"system"}
box: test: running the tests on the simulator
box: status: succeeded
box: results: saved to ./.box/out/bj_19x_hL2PNV9uyDUY/ (destinations.txt, screen.png, test.log, test-summary.json, test.xcresult.zip)
box: tests 1 passed, 0 failed
box: bj_19x_hL2PNV9uyDUY succeeded, 60s billed, $0.05
```

![The example app on an iPhone simulator after the tests: Hello from box, Count: 0, and the minus and Add buttons](https://mintcdn.com/xenoci/ZFKGlbE4Q2bw14Om/images/docs-test-screen.png?fit=max\&auto=format\&n=ZFKGlbE4Q2bw14Om\&q=85\&s=d8a038978da582f4e21da791d388ba78)

This is `out.png` from that job, made smaller for this page

> [!NOTE]
>
> Job `bj_19x_hL2PNV9uyDUY` on the production Mac: 60 s billed, \$0.05

## Run one test

```bash theme={"system"}
box test --only-testing BoxDemoTests/BoxDemoTests/testAddition
```

When the test runner never started on the Mac (a simulator problem on our side), box exits with 3, not 1: your code did not fail


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.