{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} 2. Running a test in a LostCrypt | Test Framework | 1.3.9
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    2. Running a test in a LostCrypt

    Learning Objectives

    Set up a simple Play Mode test for LostCrypt.

    Exercise

    1. Go to the Assets/Scripts directory, and spend some time exploring the scripts necessary for LostCrypt to work properly.
    2. Create a new directory Assets/Tests.
    3. In the Test Runner window click Create PlayModeTest Assembly Folder and name a new folder PlayModeTests. You should end up with Assets/Tests/PlayModeTests.
    4. Open the newly created folder and click Create Test Script in current folder in the Test Runner window.
    5. Name the file SceneSetupTests.cs.
    6. 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 Scenes/Main.unity look for GameObject FX - Day.

    Solution

    SceneSetupTests.cs

    using 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");
        }
    }
    
    In This Article
    Back to top
    Copyright © 2023 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)