unity-test-runner/README.md

276 lines
6.5 KiB
Markdown
Raw Normal View History

2019-11-30 14:48:50 +00:00
# Unity - Test runner
2020-01-29 22:54:44 +00:00
[![Actions status](https://github.com/webbertakken/unity-test-runner/workflows/Actions%20%F0%9F%98%8E/badge.svg?event=push&branch=master)](https://github.com/webbertakken/unity-test-runner/actions?query=branch%3Amaster+event%3Apush+workflow%3A"Actions%20%F0%9F%98%8E")
2019-11-30 14:46:38 +00:00
2019-12-03 22:12:31 +00:00
---
2020-01-29 22:54:44 +00:00
GitHub Action to
[run tests](https://github.com/marketplace/actions/unity-test-runner)
for any Unity project.
2019-12-03 22:12:31 +00:00
2020-01-29 22:54:44 +00:00
Part of the
[Unity Actions](https://github.com/webbertakken/unity-actions)
2019-12-03 22:12:31 +00:00
collection.
---
2019-11-30 14:46:38 +00:00
2020-01-29 22:54:44 +00:00
This is a recommended step to prepare your pipeline for using the
2019-11-30 14:46:38 +00:00
[Build](https://github.com/webbertakken/unity-actions#build)
2020-01-29 20:49:35 +00:00
action.
2019-11-30 15:36:27 +00:00
2019-11-30 17:26:15 +00:00
## Documentation
2020-01-29 22:54:44 +00:00
See the
2019-11-30 17:26:15 +00:00
[Unity Actions](https://github.com/webbertakken/unity-actions)
collection repository for workflow documentation and reference implementation.
2019-11-30 15:36:27 +00:00
## Usage
2020-01-30 23:35:41 +00:00
#### Setup test runner
By default the test runner will run all your playmode and editmode tests.
2019-12-01 00:38:59 +00:00
Create or edit the file called `.github/workflows/main.yml` and add a job to it.
2019-11-30 15:36:27 +00:00
2020-01-30 23:35:41 +00:00
##### Personal License
Personal licenses require a one-time manual activation step (per unity version).
Make sure you
[acquire and activate](https://github.com/marketplace/actions/unity-request-activation-file)
your license file and add it as a secret.
Then, define the test step as follows:
2019-11-30 15:36:27 +00:00
```yaml
2020-02-11 19:48:19 +00:00
- uses: webbertakken/unity-test-runner@v1.4
2020-01-30 23:35:41 +00:00
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
projectPath: path/to/your/project
unityVersion: 20XX.X.XXXX
2019-11-30 15:36:27 +00:00
```
2020-01-30 23:35:41 +00:00
##### Professional license
Professional licenses do not need any manual steps.
Instead, three variables will need to be set.
- `UNITY_EMAIL` (should contain the email address for your Unity account)
- `UNITY_PASSWORD` (the password that you use to login to Unity)
- `UNITY_SERIAL` (the serial provided by Unity)
Define the test step as follows:
2019-11-30 15:36:27 +00:00
```yaml
2020-02-11 19:48:19 +00:00
- uses: webbertakken/unity-test-runner@v1.4
2020-01-29 22:54:44 +00:00
env:
2020-01-30 23:35:41 +00:00
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
projectPath: path/to/your/project
unityVersion: 20XX.X.XXXX
```
2020-01-29 22:54:44 +00:00
2020-01-30 23:35:41 +00:00
That is all you need to test your project.
2020-01-29 22:54:44 +00:00
2020-01-30 23:35:41 +00:00
#### Storing test results
To be able to access the test results,
they need to be uploaded as artifacts.
To do this it is recommended to use Github Actions official
[upload artifact action](https://github.com/marketplace/actions/upload-artifact)
after any test action.
###### Using defaults
By default, Test Runner outputs it's results to a folder named `artifacts`.
Example:
```yaml
- uses: actions/upload-artifact@v1
with:
name: Test results
path: artifacts
2019-11-30 15:36:27 +00:00
```
2020-01-30 23:35:41 +00:00
Test results can now be downloaded as Artifacts in the Actions tab.
###### Specifying artifacts folder
If a different `artifactsPath` was specified in the test runner,
you can reference this path using the `id` of the test step.
Example:
2019-11-30 15:36:27 +00:00
2020-01-30 23:48:58 +00:00
```yaml
2020-02-11 19:48:19 +00:00
- uses: webbertakken/unity-test-runner@v1.4
2020-01-30 23:48:58 +00:00
id: myTestStep
(...)
```
2019-11-30 15:36:27 +00:00
```yaml
2020-01-30 23:35:41 +00:00
- uses: actions/upload-artifact@v1
2020-01-29 22:54:44 +00:00
with:
name: Test results
path: ${{ steps.myTestStep.outputs.artifactsPath }}
2019-11-30 15:36:27 +00:00
```
2020-01-30 23:35:41 +00:00
#### Caching
In order to make test runs (and builds) faster,
you can cache Library files from previous runs.
To do so, simply add Github Actions' official
[cache action](https://github.com/marketplace/actions/cache)
before any unity steps.
Example:
```yaml
- uses: actions/cache@v1.1.0
with:
path: path/to/your/project/Library
key: Library-MyProjectName-TargetPlatform
restore-keys: |
Library-MyProjectName-
Library-
```
This simple addition could speed up your test runs by more than 50%.
#### Complete example
A complete workflow that tests all modes separately could look like this:
```yaml
name: Build project
on:
pull_request: {}
push: { branches: [master] }
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
jobs:
testAllModes:
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projectPath:
- path/to/your/project
unityVersion:
- 2019.2.11f1
testMode:
- playmode
- editmode
steps:
- uses: actions/checkout@v2
with:
lfs: true
- uses: actions/cache@v1.1.0
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}
restore-keys: |
Library-
2020-02-11 19:48:19 +00:00
- uses: webbertakken/unity-test-runner@v1.4
2020-01-30 23:35:41 +00:00
id: tests
with:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
2020-01-31 00:11:30 +00:00
testMode: ${{ matrix.testMode }}
2020-01-30 23:35:41 +00:00
artifactsPath: ${{ matrix.testMode }}-artifacts
- uses: actions/upload-artifact@v1
with:
name: Test results for ${{ matrix.testMode }}
path: ${{ steps.tests.outputs.artifactsPath }}
```
> **Note:** _Environment variables are set for all jobs in the workflow like this._
## Configuration options
Below options can be specified under `with:` for the `unity-test-runner` action.
#### projectPath
Specify the path to your Unity project to be tested.
The path should be relative to the root of your project.
_**required:** `false`_
_**default:** `<your project root>`_
#### unityVersion
Version of Unity to use for testing the project.
_**required:** `false`_
_**default:** `2019.2.1f11`_
#### testMode
The type of tests to be run by the test runner.
Options are: "all", "playmode", "editmode"
_**required:** `false`_
_**default:** `all`_
#### artifactsPath
Path where the test results should be stored.
In this folder a folder will be created for every test mode.
_**required:** `false`_
_**default:** `artifacts`_
2020-04-01 20:24:13 +00:00
#### useHostNetwork
Initializes Docker using the host network.
This is useful if Unity needs to access a local server that was started as part of your workflow.
Options are: "true", "false"
_**required:** `false`_
_**default:** `false`_
2020-01-29 22:54:44 +00:00
#### customParameters
2020-01-30 23:35:41 +00:00
Custom parameters to configure the test runner.
2020-01-29 22:54:44 +00:00
Parameters must start with a hyphen (`-`) and may be followed by a value (without hyphen).
Parameters without a value will be considered booleans (with a value of true).
_**example:**_
```yaml
- uses: webbertakken/unity-test-runner@master
with:
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
```
_**required:** `false`_
_**default:** ""_
2019-11-30 15:36:27 +00:00
## More actions
2020-01-29 22:54:44 +00:00
Visit
[Unity Actions](https://github.com/webbertakken/unity-actions)
2019-11-30 15:36:27 +00:00
to find related actions for Unity.
2019-12-03 22:22:07 +00:00
Feel free to contribute.
2020-01-29 22:54:44 +00:00
## Licence
2019-12-03 22:22:07 +00:00
[MIT](./LICENSE)