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:
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: