Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,33 @@ jobs:
echo "is_unity_license_set=false" >> $GITHUB_OUTPUT
fi

test:
name: Run Unity Tests
needs: checklicense
if: needs.checklicense.outputs.is_unity_license_set == 'true'
runs-on: windows-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
with:
lfs: true

- name: Run Unity Tests
uses: game-ci/unity-test-runner@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}

- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: TestResults
path: artifacts

buildForAllSupportedPlatforms:
name: Build for ${{ matrix.targetPlatform }}
needs: checklicense
needs: [checklicense, test]
if: needs.checklicense.outputs.is_unity_license_set == 'true'
runs-on: windows-latest
strategy:
Expand Down Expand Up @@ -65,4 +89,4 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: Build-${{ matrix.targetPlatform }}
path: build/${{ matrix.targetPlatform }}
path: build/${{ matrix.targetPlatform }}
8 changes: 8 additions & 0 deletions Assets/EditorTests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions Assets/EditorTests/EditorTestScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace EditorTests
{
public class EditorTestScript
{
[Test]
public void EditorTestScriptSimplePasses()
{
try
{
var go = new GameObject("TestObject");
go.SetActive(false);
Assert.IsFalse(go.activeSelf, "GameObject should be inactive.");
Debug.Log("EditorTestScriptSimplePasses passed.");
}
catch (AssertionException e)
{
Debug.LogError($"EditorTestScriptSimplePasses failed: {e.Message}");
throw;
}
}

[UnityTest]
public IEnumerator EditorTestScriptWithEnumeratorPasses()
{
var go = new GameObject("MovableObject");
go.transform.position = Vector3.zero;
Vector3 targetPosition = new Vector3(5, 0, 0);
go.transform.position = targetPosition;
yield return null;

try
{
Assert.AreEqual(targetPosition, go.transform.position, "GameObject should move to new position.");
Debug.Log("EditorTestScriptWithEnumeratorPasses passed.");
}
catch (AssertionException e)
{
Debug.LogError($"EditorTestScriptWithEnumeratorPasses failed: {e.Message}");
throw;
}
}
}
}
2 changes: 2 additions & 0 deletions Assets/EditorTests/EditorTestScript.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EditorTests/EditorTests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "EditorTests",
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [
"Editor"
]
}
7 changes: 7 additions & 0 deletions Assets/EditorTests/EditorTests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/PlayModeTests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions Assets/PlayModeTests/PlayModeTestScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace PlayModeTests
{
public class PlayModeTestScript
{
[Test]
public void GameObject_IsCreatedWithCorrectName()
{
try
{
string expectedName = "TestObject";
GameObject go = new GameObject(expectedName);
Assert.AreEqual(expectedName, go.name);
Debug.Log("GameObject_IsCreatedWithCorrectName passed.");
}
catch (AssertionException e)
{
Debug.LogError($"GameObject_IsCreatedWithCorrectName failed: {e.Message}");
throw;
}
}

[UnityTest]
public IEnumerator GameObject_MovesAfterOneFrame()
{
GameObject go = new GameObject("MovingObject");
go.transform.position = Vector3.zero;
Vector3 targetPosition = new Vector3(0, 5, 0);
go.transform.position = targetPosition;
yield return null;

try
{
Assert.AreEqual(targetPosition, go.transform.position);
Debug.Log("GameObject_MovesAfterOneFrame passed.");
}
catch (AssertionException e)
{
Debug.LogError($"GameObject_MovesAfterOneFrame failed: {e.Message}");
throw;
}
}

[UnityTest]
public IEnumerator GameObject_WithRigidbody_FallsWithGravity()
{
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
Rigidbody rb = go.AddComponent<Rigidbody>();
go.transform.position = new Vector3(0, 10, 0);

yield return new WaitForSeconds(0.5f);

try
{
Assert.Less(go.transform.position.y, 10f, "Rigidbody should have fallen due to gravity.");
Debug.Log("GameObject_WithRigidbody_FallsWithGravity passed.");
}
catch (AssertionException e)
{
Debug.LogError($"GameObject_WithRigidbody_FallsWithGravity failed: {e.Message}");
throw;
}
}
}
}
2 changes: 2 additions & 0 deletions Assets/PlayModeTests/PlayModeTestScript.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Assets/PlayModeTests/PlayModeTests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "PlayModeTests",
"optionalUnityReferences": [
"TestAssemblies"
]
}
7 changes: 7 additions & 0 deletions Assets/PlayModeTests/PlayModeTests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading