diff --git a/Runtime/Attributes/CreateSceneAttribute.cs b/Runtime/Attributes/CreateSceneAttribute.cs index abefff9..f547101 100644 --- a/Runtime/Attributes/CreateSceneAttribute.cs +++ b/Runtime/Attributes/CreateSceneAttribute.cs @@ -43,21 +43,31 @@ public CreateSceneAttribute(bool camera = false, bool light = false) public IEnumerator BeforeTest(ITest test) { _newSceneName = $"Scene of {TestContext.CurrentContext.Test.FullName}"; -#if UNITY_EDITOR - if (EditorApplication.isPlaying) + + if (Application.isEditor) { - var scene = SceneManager.CreateScene(_newSceneName); - SceneManager.SetActiveScene(scene); +#if UNITY_EDITOR + if (Application.isPlaying) + { + // Play Mode tests running in Editor + var scene = SceneManager.CreateScene(_newSceneName); + SceneManager.SetActiveScene(scene); + } + else + { + // Edit Mode tests + var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene); + scene.name = _newSceneName; + } +#endif } else { - var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene); - scene.name = _newSceneName; - } -#else + // Play Mode tests running on Player var scene = SceneManager.CreateScene(_newSceneName); SceneManager.SetActiveScene(scene); -#endif + } + if (_camera) { var camera = new GameObject("Main Camera").AddComponent(); diff --git a/Runtime/Attributes/LoadSceneAttribute.cs b/Runtime/Attributes/LoadSceneAttribute.cs index 1b072b5..733ae30 100644 --- a/Runtime/Attributes/LoadSceneAttribute.cs +++ b/Runtime/Attributes/LoadSceneAttribute.cs @@ -26,7 +26,7 @@ namespace TestHelper.Attributes /// /// Notes: /// - Load scene run after OneTimeSetUp and before SetUp - /// - For the process of including a Scene not in "Scenes in Build" to a build for player, see: + /// - For the process of including a Scene not in "Scenes in Build" to a build for player, see: /// [AttributeUsage(AttributeTargets.Method)] public class LoadSceneAttribute : NUnitAttribute, IOuterUnityTestAction @@ -50,22 +50,30 @@ public LoadSceneAttribute(string path) public IEnumerator BeforeTest(ITest test) { AsyncOperation loadSceneAsync = null; -#if UNITY_EDITOR - if (EditorApplication.isPlaying) + + if (Application.isEditor) { - // Use EditorSceneManager at run on Unity-editor - loadSceneAsync = EditorSceneManager.LoadSceneAsyncInPlayMode( - ScenePath, - new LoadSceneParameters(LoadSceneMode.Single)); +#if UNITY_EDITOR + if (Application.isPlaying) + { + // Play Mode tests running in Editor + loadSceneAsync = EditorSceneManager.LoadSceneAsyncInPlayMode( + ScenePath, + new LoadSceneParameters(LoadSceneMode.Single)); + } + else + { + // Edit Mode tests + EditorSceneManager.OpenScene(ScenePath); + } +#endif } else { - EditorSceneManager.OpenScene(ScenePath); + // Play Mode tests running on Player + loadSceneAsync = SceneManager.LoadSceneAsync(ScenePath); } -#else - // Use ITestPlayerBuildModifier to change the "Scenes in Build" list before run on player - loadSceneAsync = SceneManager.LoadSceneAsync(ScenePath); -#endif + yield return loadSceneAsync; }