docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Introduction to UI test fixtures

    The UI test fixtures are base classes that your test classes can inherit from. The test fixtures manage the lifetime (set up and tear down) of your test's UI. Depending on the test fixture, they can provide your test with an empty UI ready for you to populate, or they can spawn an existing UI you provide to it.

    Choose the appropriate test fixture

    There are 4 test fixtures available to use. The following table summarizes each test fixture and its intended purpose:

    Test fixture Intended purpose
    UITestFixture Create tests that run in both Editor and Runtime states. This fixture provides an empty panel instance for you to populate during the test.
    EditorWindowUITestFixture Create tests that require an actual EditorWindow instance. This fixture spawns and manages an EditorWindow instance for you.
    RuntimeUITestFixture Create tests that run in the runtime state. This fixture provides an empty UIDocument object for runtime testing.
    DebugUITestFixture Create tests that temporarily create an actual EditorWindow instance for debugging purposes.

    The following decision tree can help you decide which test fixture to use based on how you structure your UI:

    flowchart TD A{{Are you testing an EditorWindow?}} B{{Are you testing a UI in a scene?}} C("UITestFixture <span style='font-size:10px;'>Can be used in Editor or Runtime</span>") D(EditorWindowUITestFixture) E(RuntimeUITestFixture) A --> |No| B A --> |"Yes, my window logic relies on <span style='font-family:Courier New;'>CreateGUI()</span> or <span style='font-family:Courier New;'>GUIView</span> to run properly"| D B --> |No, I only need my UXML or custom controls| C B --> |Yes, my UI logic relies on my GameObject with a UIDocument component| E classDef question fill:#FFF class A,B question click D "test-ui-with-editor-window-instances.html" "Test UI with Editor window instances" click E "test-ui-in-runtime.html" "Test UI in runtime" click C "test-in-both-editor-and-runtime-states.html" "Test in both Editor and runtime states"

    PanelSimulator

    A key aspect of the test fixtures is the PanelSimulator. Each test fixture initializes a simulate property, which inherits from the PanelSimulator base class. This property allows you to control the timing of your UI, update the UI as needed, and simulate user interactions and events.

    There are different types of PanelSimulator, each designed to work in specific environments or scenarios. For more information about the different types of PanelSimulator and which test fixture uses which type, refer to Create multi-window tests.

    Test fixture properties

    The test fixtures share common base classes and therefore have some common properties that are important to know for writing tests.

    The following table summarizes several important properties for writing tests.

    Common Property Description
    simulate Use this property to simulate events, simulate time increments, and update your UI.
    rootVisualElement Use this property to modify your UI, add or remove elements, or query for elements.

    For a complete reference of all the common properties and methods, refer to AbstractUITestFixture and CommonUITestFixture.

    Test fixture class diagram

    This class diagram illustrates the relationships between the different test fixtures:

    --- config: class: hideEmptyMembersBox: true --- classDiagram direction TB class AbstractUITestFixture { } class CommonUITestFixture { } class RuntimeUITestFixture { } class UITestFixture { } class EditorUITestFixture { } style AbstractUITestFixture fill:#FFF style CommonUITestFixture fill:#FFF style EditorUITestFixture fill:#FFF <<internal>> AbstractUITestFixture <<internal>> CommonUITestFixture <<internal>> EditorUITestFixture namespace Editor { class EditorWindowUITestFixture { } class EditorUITestFixture { } class DebugUITestFixture { } class UITestFixture { } } namespace Runtime { class RuntimeUITestFixture { } class UITestFixture { } } AbstractUITestFixture <|-- CommonUITestFixture CommonUITestFixture <|-- EditorUITestFixture CommonUITestFixture <|-- EditorWindowUITestFixture CommonUITestFixture <|-- RuntimeUITestFixture EditorWindowUITestFixture <|-- DebugUITestFixture AbstractUITestFixture <|-- UITestFixture RuntimeUITestFixture <|.. UITestFixture : can instantiate EditorUITestFixture <|.. UITestFixture : can instantiate

    Additional resources

    • EditorWindow
    • PanelSimulator
    • Panels
    In This Article
    Back to top
    Copyright © 2025 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)