Version: Unity 7.0 Alpha (7000.0)
Language : English
1. Setting up LostCrypt
3. Moving character

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

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");
    }
}
1. Setting up LostCrypt
3. Moving character
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961