docs.unity3d.com

    Recorded Testing

    Recorded Playbacks (recordings) can be used to "drive" a Unity Test, combining the simplicity of recorded playback creation with the flexibility and power of the Unity Test Framework.

    Generated Recorded Tests

    Menu: Tools > Automated Testing > Generate Recorded Tests

    Generate Recorded Tests to automatically create unit tests for the recordings in the Assets/Recordings directory. These tests can be run from the Unity Test Runner window.

    The following unit tests are generated automatically for each recording:

    • PlayToEnd - Asserts that the recording can successfully play through to the end.

    Custom Recorded Tests

    To "drive" a UnityTest with a recorded playback, add [RecordedTest("[relative path of recording (relative to /Assets)]")] right after the test's existing [UnityTest] attribute.

    For example, to validate that a tutorial loads as expected:

    1. Create a recorded playback that ends with the tutorial loading
    2. Rename the resulting recording-[timestamp].json file to something more descriptive like "load_tutorial.json"
    3. Create a new Unity Test with [RecordedTest("Recordings/load_tutorial.json")] below the [UnityTest] attribute
    4. Inside the Unity Test: a. Load the scene where your recording begins, e.g. SceneManager.LoadScene("0_Title"); b. Once playback is complete or some period of time has passed, Assert that some key condition is true

    Example RecordedTest usage:

    namespace Tests
    {
        public class SmokeTests : RecordedTestSuite
        {
            [UnityTest]
            [RecordedTest("Recordings/load_tutorial.json.json")]
            public IEnumerator validate_tutorial_loads()
            {
               SceneManager.LoadScene("0_Title");
               ...
    
               //wait until the Tutorial scene loads
               while (SceneManager.GetActiveScene().name != "Tutorial")
               {
                   yield return null;
               }
    
               Assert.NotNull(GameObject.Find("Tutorial_Manager");
            }
    
        }
    }
    
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023