Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CreateSceneAttribute tests #19

Merged
merged 2 commits into from
Oct 22, 2023
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
19 changes: 5 additions & 14 deletions Runtime/Attributes/CreateSceneAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,17 @@ public IEnumerator BeforeTest(ITest test)
{
_newSceneName = $"Scene of {TestContext.CurrentContext.Test.FullName}";

if (Application.isEditor)
if (Application.isEditor && !Application.isPlaying)
{
#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;
}
// Edit Mode tests
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
scene.name = _newSceneName;
#endif
}
else
{
// Play Mode tests running on Player
// Play Mode tests
var scene = SceneManager.CreateScene(_newSceneName);
SceneManager.SetActiveScene(scene);
}
Expand Down
18 changes: 8 additions & 10 deletions Tests/Runtime/Attributes/CreateSceneAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;

Expand All @@ -21,11 +20,8 @@ public void Attach_CreateNewSceneWithoutCameraAndLight()
Assert.That(scene.name, Is.EqualTo(
"Scene of TestHelper.Attributes.CreateSceneAttributeTest.Attach_CreateNewSceneWithoutCameraAndLight"));

var camera = GameObject.Find("Main Camera");
Assert.That(camera, Is.Null);

var light = GameObject.Find("Directional Light");
Assert.That(light, Is.Null);
var rootGameObjects = scene.GetRootGameObjects(); // Note: GameObject.Find finds objects in inactive scenes
Assert.That(rootGameObjects, Is.Empty);
}

[Test]
Expand All @@ -36,8 +32,9 @@ public void Attach_WithCamera_CreateNewSceneWithCamera()
Assert.That(scene.name, Is.EqualTo(
"Scene of TestHelper.Attributes.CreateSceneAttributeTest.Attach_WithCamera_CreateNewSceneWithCamera"));

var camera = GameObject.Find("Main Camera");
Assert.That(camera, Is.Not.Null);
var rootGameObjects = scene.GetRootGameObjects(); // Note: GameObject.Find finds objects in inactive scenes
Assert.That(rootGameObjects, Has.Length.EqualTo(1));
Assert.That(rootGameObjects[0].name, Is.EqualTo("Main Camera"));
}

[Test]
Expand All @@ -48,8 +45,9 @@ public void Attach_WithLight_CreateNewSceneWithLight()
Assert.That(scene.name, Is.EqualTo(
"Scene of TestHelper.Attributes.CreateSceneAttributeTest.Attach_WithLight_CreateNewSceneWithLight"));

var light = GameObject.Find("Directional Light");
Assert.That(light, Is.Not.Null);
var rootGameObjects = scene.GetRootGameObjects(); // Note: GameObject.Find finds objects in inactive scenes
Assert.That(rootGameObjects, Has.Length.EqualTo(1));
Assert.That(rootGameObjects[0].name, Is.EqualTo("Directional Light"));
}

[Test]
Expand Down