docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Test UI in runtime

    Use RuntimeUITestFixture to create tests that run in Play mode. This fixture allows you to load and test an existing Scene containing your UI.

    The following examples show how to set up your test class to use RuntimeUITestFixture in a Play mode test assembly.

    Test UI made with UIDocument

    After loading the Scene, fetch the UIDocument object and call SetUIContent to hook up your UI for simulation.

    // This class is contained in a runtime test assembly.
    public class BasicUIDocumentRuntimeExampleClass : RuntimeUITestFixture
    {
        [UnityOneTimeSetUp]
        public IEnumerator UnityOneTimeSetUp()
        {
            // Load the scene and yield a player
            // frame to ensure it is up to date.
            yield return SceneManager.LoadSceneAsync("UIDocumentTestScene", LoadSceneMode.Single);
            yield return null;
        }
    
        [Test]
        public void BasicRuntimeExampleTest()
        {
            // Fetch the UIDocument from the Scene.
            GameObject gameObject = GameObject.Find("UIDocument");
            UIDocument uiDocument = gameObject.GetComponent<UIDocument>();
    
            // Hook up the UIDocument for simulation.
            SetUIContent(uiDocument);
    
            simulate.FrameUpdate();
    
            Button button = rootVisualElement.Q<Button>("MyButton");
            Assert.That(button, Is.Not.Null);
    
            // Test steps.
            // ...
        }
    }
    

    Test UI made with PanelRenderer

    After loading the Scene, fetch the PanelRenderer object and call SetPanelRenderer to hook up your UI for simulation.

    // This class is contained in a runtime test assembly.
    public class BasicPanelRendererRuntimeExampleClass : RuntimeUITestFixture
    {
        [UnityOneTimeSetUp]
        public IEnumerator UnityOneTimeSetUp()
        {
            // Load the scene and yield a player
            // frame to ensure it is up to date.
            yield return SceneManager.LoadSceneAsync("PanelRendererTestScene", LoadSceneMode.Single);
            yield return null;
        }
    
        [Test]
        public void BasicRuntimeExampleTest()
        {
            // Fetch the PanelRenderer from the Scene.
            PanelRenderer panelRenderer = GameObject.FindFirstObjectByType<PanelRenderer>();
    
            // Hook up the PanelRenderer for simulation.
            SetPanelRenderer(panelRenderer);
    
            simulate.FrameUpdate();
    
            Button button = rootVisualElement.Q<Button>("MyButton");
            Assert.That(button, Is.Not.Null);
    
            // Test steps. 
            // ...
        }
    }
    

    Additional resources

    • Test in both Editor and runtime states
    In This Article
    Back to top
    Copyright © 2026 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)