# Test results cache

> Test targets whose built products passed before are skipped, with that result.

Source: https://warmbuild.dev/docs/test-results/

**What you do**

1. Build the tests with `xcodebuild build-for-testing` into a known DerivedData.
2. Add the test-cache step right after it.

   ``` title=".github/workflows/build.yml"
   - uses: warmbuild/action/test-cache@v1.14.2
     id: tests
     with:
       derived-data: ${{ runner.temp }}/dd
       destination: id=${{ env.UDID }}
   ```
3. Run `test-without-building` with `$WARMBUILD_ONLY_TESTING`, unless `tests` is `none`.

**What you get**

Test targets whose built products passed before are skipped and reported with that run's result. When every target passed before, the Simulator need not boot.

Optional, on pushes and pull requests: the `warmbuild/action/test-cache` step goes between `xcodebuild build-for-testing` and `xcodebuild test-without-building`.

- **The key:** one per test target, from every product the tests load (the test bundle, its host app, the UI test runner), the target’s settings in the `.xctestrun`, the destination’s runtime and device type, and the Xcode version.
- **What it writes:** `$WARMBUILD_ONLY_TESTING` with the workflow’s own `args`, test selection’s arguments, and `-skip-testing` for each reused target. Pass it to `test-without-building`.
- **Nothing left to run:** the step’s `tests` output is `none`; skip the Simulator boot and the test step with `if: steps.tests.outputs.tests != 'none'`.
- **Anything else that changes results** (a fixture version, a server under test) goes in `extra-key`. `cache-tests: false` runs every target and still records the ones that pass.
- **The job summary** lists each target as reused (with the run and commit it came from) or run.

### Swift packages

Package tests and package builds (`swift test`, a package’s `xcodebuild build`) have no products to hash first. The `warmbuild/action/step-cache` step keys them instead, and skips the command when that key passed before:

- every file of the package and its local dependencies, and `Package.resolved`;
- the command, Xcode and the destination.

Inputs and a full workflow are in the [Action’s README](https://github.com/warmbuild/action).
