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:
- Create a recorded playback that ends with the tutorial loading
- Rename the resulting
recording-[timestamp].jsonfile to something more descriptive like "load_tutorial.json" - Create a new Unity Test with
[RecordedTest("Recordings/load_tutorial.json")]below the[UnityTest]attribute - 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");
}
}
}