2. Running a test in a LostCrypt
Set up a simple Play mode test for LostCrypt.
Read time 1 minuteLast updated 14 days ago
Learning Objectives
Set up a simple Play Mode test for LostCrypt.
Exercise
- Go to the directory, and spend some time exploring the scripts necessary for LostCrypt to work properly.
Assets/Scripts - Create a new directory .
Assets/Tests - In the Test Runner window click Create PlayModeTest Assembly Folder and name a new folder . You should end up with
PlayModeTests.Assets/Tests/PlayModeTests - Open the newly created folder and click Create Test Script in current folder in the Test Runner window.
- Name the file .
SceneSetupTests.cs - Write your first test that asserts that after loading the Main scene the current time is day.
Hints
- In order to load scenes, please refer to UnityEngine.SceneManagement documentation.
- Inside look for GameObject FX - Day.
Scenes/Main.unity
Solution
SceneSetupTests.csusing System.Collections;using System.Collections.Generic;using NUnit.Framework;using UnityEngine;using UnityEngine.TestTools;using UnityEngine.SceneManagement;public class SceneSetupTests{ [UnityTest] public IEnumerator MainScene_LoadsCorrectlyAndItsDaytime() { SceneManager.LoadScene("Assets/Scenes/Main.unity", LoadSceneMode.Single); yield return null; var fxDay = GameObject.Find("FX - Day"); Assert.IsTrue(fxDay != null, "should find the 'FX - Day' object in the scene"); }}