diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index ca7facf..47fe2a5 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -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: @@ -65,4 +89,4 @@ jobs: - uses: actions/upload-artifact@v4 with: name: Build-${{ matrix.targetPlatform }} - path: build/${{ matrix.targetPlatform }} + path: build/${{ matrix.targetPlatform }} \ No newline at end of file diff --git a/Assets/EditorTests.meta b/Assets/EditorTests.meta new file mode 100644 index 0000000..ff970de --- /dev/null +++ b/Assets/EditorTests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e52f4ee92d306804fa40425026db7827 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/EditorTests/EditorTestScript.cs b/Assets/EditorTests/EditorTestScript.cs new file mode 100644 index 0000000..32134b2 --- /dev/null +++ b/Assets/EditorTests/EditorTestScript.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/Assets/EditorTests/EditorTestScript.cs.meta b/Assets/EditorTests/EditorTestScript.cs.meta new file mode 100644 index 0000000..b026cf1 --- /dev/null +++ b/Assets/EditorTests/EditorTestScript.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 602da79533fedf04aae657555385ffca \ No newline at end of file diff --git a/Assets/EditorTests/EditorTests.asmdef b/Assets/EditorTests/EditorTests.asmdef new file mode 100644 index 0000000..ebe11f8 --- /dev/null +++ b/Assets/EditorTests/EditorTests.asmdef @@ -0,0 +1,9 @@ +{ + "name": "EditorTests", + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [ + "Editor" + ] +} \ No newline at end of file diff --git a/Assets/EditorTests/EditorTests.asmdef.meta b/Assets/EditorTests/EditorTests.asmdef.meta new file mode 100644 index 0000000..26f8c32 --- /dev/null +++ b/Assets/EditorTests/EditorTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e6347d5d0ed28bd44a6c11c24cff7d6a +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PlayModeTests.meta b/Assets/PlayModeTests.meta new file mode 100644 index 0000000..ee0a34c --- /dev/null +++ b/Assets/PlayModeTests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed650271217c7a34a941f8ce29001b2f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PlayModeTests/PlayModeTestScript.cs b/Assets/PlayModeTests/PlayModeTestScript.cs new file mode 100644 index 0000000..1ede77d --- /dev/null +++ b/Assets/PlayModeTests/PlayModeTestScript.cs @@ -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(); + 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; + } + } + } +} \ No newline at end of file diff --git a/Assets/PlayModeTests/PlayModeTestScript.cs.meta b/Assets/PlayModeTests/PlayModeTestScript.cs.meta new file mode 100644 index 0000000..129fff6 --- /dev/null +++ b/Assets/PlayModeTests/PlayModeTestScript.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 5f30bf992d74eb44db225c41cd1aa82c \ No newline at end of file diff --git a/Assets/PlayModeTests/PlayModeTests.asmdef b/Assets/PlayModeTests/PlayModeTests.asmdef new file mode 100644 index 0000000..c978340 --- /dev/null +++ b/Assets/PlayModeTests/PlayModeTests.asmdef @@ -0,0 +1,6 @@ +{ + "name": "PlayModeTests", + "optionalUnityReferences": [ + "TestAssemblies" + ] +} diff --git a/Assets/PlayModeTests/PlayModeTests.asmdef.meta b/Assets/PlayModeTests/PlayModeTests.asmdef.meta new file mode 100644 index 0000000..ed29b28 --- /dev/null +++ b/Assets/PlayModeTests/PlayModeTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0ec9f341397255e49baea5fd05f882f9 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: