diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7341d4..d643eca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,8 +46,8 @@ jobs: - 6000.0.43f1 # Latest version that does not pin the test framework package. - 6000.0.44f1 # pin test-framework v1.5.1 - 6000.0.59f2 # pin test-framework v1.6.0 - - 6000.0.78f1 - - 6000.3.18f1 + - 6000.0.85f1 + - 6000.3.28f1 - &latest_unity_version 6000.5.1f1 # pin test-framework v1.7.0 testMode: - All # run tests in editor diff --git a/Assets/APIExamples/Tests/Editor/UnityTestFramework/EditModeTestYieldInstructionExample.cs b/Assets/APIExamples/Tests/Editor/UnityTestFramework/EditModeTestYieldInstructionExample.cs index 6aa6a7b..92bba73 100644 --- a/Assets/APIExamples/Tests/Editor/UnityTestFramework/EditModeTestYieldInstructionExample.cs +++ b/Assets/APIExamples/Tests/Editor/UnityTestFramework/EditModeTestYieldInstructionExample.cs @@ -26,9 +26,10 @@ public class EditModeTestYieldInstructionExample private static bool s_wasUnitySetUpCalled; private static bool s_wasSetUpCalled; private static bool s_wasSetUpAsyncCalled; + private static bool s_isDomainReloadPending; - private const string CsPath = "Assets/CreateFileExample.cs"; - private const string RspPath = "Assets/csc.rsp"; + private const string CsPath = "Assets/APIExamples/Scripts/Runtime/CreateFileExample.cs"; + private const string RspPath = "Assets/APIExamples/Scripts/Runtime/csc.rsp"; private const string DLLSrcPath = "TestData/NativePluginExample.dll"; private const string DLLDstPath = "Assets/NativePluginExample.dll"; @@ -119,7 +120,18 @@ public void TearDown() Assert.That(EditorApplication.isPlaying, Is.False); } + private static IEnumerator WaitForPendingDomainReload() + { + // Note: RecompileScriptsはコンパイル完了までしか待たず、ドメインリロードが遅れて実行されることがあるため待機する。 + // WaitForDomainReloadを使わないのは、ドメインリロードがRecompileScripts中に完了していると例外をスローするため + while (s_isDomainReloadPending) + { + yield return null; + } + } + [UnityTest] + [Timeout(60000)] public IEnumerator RecompileScriptsでリコンパイルを実行する例_リコンパイルされたクラスのメソッドを呼び出せる() { Assume.That(Path.GetFullPath(CsPath), Does.Not.Exist, @@ -130,11 +142,14 @@ public void TearDown() file.Write("public class Foo { public bool Bar(string msg) { return true; } }"); } + s_isDomainReloadPending = true; + // ここでAssetDatabase.Refresh()は不要 yield return new RecompileScripts(); + yield return WaitForPendingDomainReload(); // リフレクションでメソッド呼び出し - var assemblyName = new AssemblyName("Assembly-CSharp"); + var assemblyName = new AssemblyName("APIExamples"); var assembly = Assembly.Load(assemblyName); var fooType = assembly.GetType("Foo"); dynamic foo = Activator.CreateInstance(fooType); @@ -144,6 +159,7 @@ public void TearDown() } [UnityTest] + [Timeout(60000)] public IEnumerator RecompileScriptsでリコンパイルを実行する例_csc_rspで追加したスクリプティングシンボルが有効になる() { Assume.That(Path.GetFullPath(RspPath), Does.Not.Exist, @@ -161,9 +177,14 @@ public void TearDown() "#endif\n" + "} }"); + s_isDomainReloadPending = true; + + // ここでAssetDatabase.Refresh()は不要 yield return new RecompileScripts(); + yield return WaitForPendingDomainReload(); - var assembly = Assembly.Load(new AssemblyName("Assembly-CSharp")); + // リフレクションでメソッド呼び出し + var assembly = Assembly.Load(new AssemblyName("APIExamples")); var fooType = assembly.GetType("Foo"); var actual = (bool)fooType.GetMethod("IsDefined")!.Invoke(null, null);