Skip to content

Commit d6cd0c1

Browse files
authored
Merge pull request #59 from IShix-g/release
feat: add Unity test setup for EditMode and PlayMode
2 parents e75b1af + bbfd6d5 commit d6cd0c1

16 files changed

+384
-4
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: (Reusable) Test Runner
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
unity-version:
7+
description: 'Version of Unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt. ⚠️ If testing a Unity Package, this field is required and cannot be set to "auto". https://game.ci/docs/docker/versions/'
8+
required: false
9+
type: string
10+
default: 'auto'
11+
project-path:
12+
description: 'Specify the path to your Unity project or package to be tested. The path should be relative to the root of your project.'
13+
required: false
14+
type: string
15+
default: ''
16+
test-modes:
17+
description: 'Comma-separated test modes (e.g., playmode,editmode,standalone).'
18+
required: false
19+
type: string
20+
default: 'playmode,editmode'
21+
custom-parameters:
22+
description: 'Custom parameters to configure the test runner. https://game.ci/docs/github/test-runner/#customparameters'
23+
required: false
24+
type: string
25+
default: ''
26+
secrets:
27+
UNITY_LICENSE:
28+
required: true
29+
UNITY_EMAIL:
30+
required: true
31+
UNITY_PASSWORD:
32+
required: true
33+
34+
jobs:
35+
prepare-test-modes:
36+
runs-on: ubuntu-latest
37+
outputs:
38+
array: ${{ steps.set-array.outputs.array }}
39+
steps:
40+
- name: Convert test modes to array
41+
id: set-array
42+
run: |
43+
if [[ "${{ inputs.test-modes }}" == *","* ]]; then
44+
echo '::set-output name=array::["'$(echo "${{ inputs.test-modes }}" | sed 's/,/","/g')'"]'
45+
else
46+
echo '::set-output name=array::["${{ inputs.test-modes }}"]'
47+
fi
48+
49+
test-all:
50+
name: Test in ${{ matrix.testMode }}
51+
runs-on: ubuntu-22.04
52+
timeout-minutes: 20
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
unity-version: ${{ inputs.unity-version }}
57+
projectPath: ${{ inputs.project-path }}
58+
testMode: ${{ fromJson(needs.prepare-test-modes.outputs.array) }}
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
with:
63+
lfs: true
64+
- uses: actions/cache@v3
65+
with:
66+
path: ${{ matrix.projectPath }}/Library
67+
key: Library-${{ matrix.projectPath }}
68+
restore-keys: |
69+
Library-
70+
- uses: game-ci/unity-test-runner@v4
71+
id: tests
72+
env:
73+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
74+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
75+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
76+
with:
77+
projectPath: ${{ matrix.projectPath }}
78+
testMode: ${{ matrix.testMode }}
79+
artifactsPath: ${{ matrix.testMode }}-artifacts
80+
githubToken: ${{ secrets.GITHUB_TOKEN }}
81+
checkName: ${{ matrix.testMode }} Test Results
82+
- uses: actions/upload-artifact@v3
83+
if: always()
84+
with:
85+
name: Test results for ${{ matrix.testMode }}
86+
path: ${{ steps.tests.outputs.artifactsPath }}
87+
- uses: actions/upload-artifact@v3
88+
if: always()
89+
with:
90+
name: Coverage results for ${{ matrix.testMode }}
91+
path: ${{ steps.tests.outputs.coveragePath }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: (Test) Test Runner
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
unity-version:
7+
description: 'Select the Unity version to use'
8+
required: true
9+
default: '2021.3.45f1'
10+
type: choice
11+
options:
12+
- '2021.3.45f1'
13+
- '2022.3.57f1'
14+
- '6000.0.37f1'
15+
jobs:
16+
test-runner:
17+
uses: ./.github/workflows/reusable-test-runner.yaml
18+
secrets:
19+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
20+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
21+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
22+
inputs:
23+
unity-version: ${{ inputs.unity-version }}

Assets/Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/EditoMode.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
using NUnit.Framework;
3+
using UnityEditor;
4+
5+
namespace Tests
6+
{
7+
public class EditorTests
8+
{
9+
[Test]
10+
public void SampleEditorTest1()
11+
{
12+
Assert.That(1 + 1, Is.EqualTo(2), "1 + 1 should equal 2");
13+
}
14+
15+
[Test]
16+
public void SampleEditorTest2()
17+
{
18+
var activeScenePath = EditorApplication.currentScene;
19+
Assert.That(activeScenePath, Is.Not.Null, "There should be an active scene in the editor.");
20+
}
21+
22+
[Test]
23+
public void SampleEditorTest3()
24+
{
25+
Assert.That(EditorPrefs.HasKey("EditorTests_SampleEditorTest3_TestKey"), Is.False, "EditorPrefs should have a key.");
26+
}
27+
}
28+
}

Assets/Tests/EditoMode/EditorTests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
using NUnit.Framework;
3+
using UnityEditor;
4+
5+
namespace Tests
6+
{
7+
public sealed class EditorTests2
8+
{
9+
[Test]
10+
public void BasicMathTest()
11+
{
12+
Assert.That(5 * 2, Is.EqualTo(10), "5 multiplied by 2 should equal 10.");
13+
}
14+
15+
[Test]
16+
public void EditorPrefsTest()
17+
{
18+
var testKey = "SampleTestKey";
19+
var testValue = "SampleValue";
20+
21+
EditorPrefs.SetString(testKey, testValue);
22+
23+
Assert.That(EditorPrefs.HasKey(testKey), Is.True, "EditorPrefs should contain the key.");
24+
Assert.That(EditorPrefs.GetString(testKey), Is.EqualTo(testValue), "EditorPrefs should return the correct value.");
25+
26+
EditorPrefs.DeleteKey(testKey);
27+
Assert.That(EditorPrefs.HasKey(testKey), Is.False, "EditorPrefs key should be deleted.");
28+
}
29+
}
30+
}

Assets/Tests/EditoMode/EditorTests2.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Tests.EditMode",
3+
"rootNamespace": "",
4+
"references": [
5+
"UnityEngine.TestRunner",
6+
"UnityEditor.TestRunner"
7+
],
8+
"includePlatforms": [
9+
"Editor"
10+
],
11+
"excludePlatforms": [],
12+
"allowUnsafeCode": false,
13+
"overrideReferences": true,
14+
"precompiledReferences": [
15+
"nunit.framework.dll"
16+
],
17+
"autoReferenced": false,
18+
"defineConstraints": [
19+
"UNITY_INCLUDE_TESTS"
20+
],
21+
"versionDefines": [],
22+
"noEngineReferences": false
23+
}

Assets/Tests/EditoMode/Tests.EditMode.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)