GitHub Action to run tests for any Unity project.
Part of the Unity Actions collection.
This is a recommended step to prepare your pipeline for using the Build action.
See the Unity Actions collection repository for workflow documentation and reference implementation.
By default the test runner will run all your playmode and editmode tests.
Create or edit the file called .github/workflows/main.yml and add a job to it.
Personal licenses require a one-time manual activation step (per unity version).
Make sure you acquire and activate your license file and add it as a secret.
Then, define the test step as follows:
- uses: webbertakken/unity-test-runner@v1.4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
projectPath: path/to/your/project
unityVersion: 20XX.X.XXXXProfessional 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:
- uses: webbertakken/unity-test-runner@v1.4
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
projectPath: path/to/your/project
unityVersion: 20XX.X.XXXXThat is all you need to test your project.
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 after any test action.
By default, Test Runner outputs it's results to a folder named artifacts.
Example:
- uses: actions/upload-artifact@v1
with:
name: Test results
path: artifactsTest results can now be downloaded as Artifacts in the Actions tab.
If a different artifactsPath was specified in the test runner,
you can reference this path using the id of the test step.
Example:
- uses: webbertakken/unity-test-runner@v1.4
id: myTestStep
(...)- uses: actions/upload-artifact@v1
with:
name: Test results
path: ${{ steps.myTestStep.outputs.artifactsPath }}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 before any unity steps.
Example:
- 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%.
A complete workflow that tests all modes separately could look like this:
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-
- uses: webbertakken/unity-test-runner@v1.4
id: tests
with:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
testMode: ${{ matrix.testMode }}
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.
Below options can be specified under with: for the unity-test-runner action.
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>
Version of Unity to use for testing the project.
required: false
default: 2019.2.1f11
The type of tests to be run by the test runner.
Options are: "all", "playmode", "editmode"
required: false
default: all
Path where the test results should be stored.
In this folder a folder will be created for every test mode.
required: false
default: artifacts
Custom parameters to configure the test runner.
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:
- uses: webbertakken/unity-test-runner@master
with:
customParameters: -profile SomeProfile -someBoolean -someValue exampleValuerequired: false
default: ""
Visit Unity Actions to find related actions for Unity.
Feel free to contribute.