KitchenChaos/Library/PackageCache/com.unity.test-framework@1.3.2/Samples~/12_BuildSetupCleanup/PlayModeTests/SceneTests.cs

42 lines
1.2 KiB
C#

using System.Collections;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
namespace Tests
{
public class SceneTests
{
private string originalScene;
private const string k_SceneName = "Assets/MyGameScene.unity";
[UnitySetUp]
public IEnumerator SetupBeforeTest()
{
originalScene = SceneManager.GetActiveScene().path;
if (!File.Exists(k_SceneName))
{
Assert.Inconclusive("The path to the Scene is not correct. Set the correct path for the k_SceneName variable.");
}
SceneManager.LoadScene(k_SceneName);
yield return null; // Skip a frame, allowing the scene to load.
}
[Test]
public void VerifyScene()
{
var gameObject = GameObject.Find("GameObjectToTestFor");
Assert.That(gameObject, Is.Not.Null, $"GameObjectToTestFor not found in {SceneManager.GetActiveScene().path}.");
}
[TearDown]
public void TeardownAfterTest()
{
SceneManager.LoadScene(originalScene);
}
}
}