Create multi-window tests
The test fixtures instantiate one panel and manage its lifetime for you. However, some tests require multiple panels or windows to simulate complex UI interactions. You can create and manage multiple PanelSimulator instances in your tests to achieve this. Each PanelSimulator can represent a different panel or window, allowing you to test interactions between them.
PanelSimulator types
There are different types of PanelSimulator, each designed to work in specific environments or scenarios. The test fixture you select determines what type of UI the test fixture initializes.
The following table summarizes the different PanelSimulator types used by each test fixture:
| Test fixture | Simulator Type | Description |
|---|---|---|
| UITestFixture | RuntimePanelSimulator or EditorPanelSimulator | Simulates a panel in either the runtime or Editor environment. |
| DebugUITestFixture | EditorWindowPanelSimulator | Simulates a panel within an Editor window. |
| EditorWindowUITestFixture | EditorWindowPanelSimulator | Simulates a panel within an Editor window. |
| RuntimeUITestFixture | RuntimePanelSimulator | Simulates a panel in the runtime environment. |
Example
The following example shows how to create multiple EditorWindowPanelSimulator instances in a test:
public class SimulateMultipleWindows : EditorWindowUITestFixture<UITestFrameworkDocSampleWindow>
{
[Test]
public void MultipleWindowsExampleTest()
{
// Use the CleanupUtil UITestComponent to manage the ScriptableObject cleanup.
CleanupUtil cleanupUtil = AddTestComponent<CleanupUtil>();
// Ensure the main test UI is updated.
simulate.FrameUpdate();
// Create a new EditorWindow for testing.
EditorWindow window = ScriptableObject.CreateInstance<EditorWindow>();
window.Show();
// Ensure the new window will be properly destroyed.
cleanupUtil.AddDestructible(window);
// Hook up the EditorWindow as a simulator.
EditorWindowPanelSimulator secondEditorWindow =
new EditorWindowPanelSimulator(window);
// Ensure the UI for the second window is updated.
secondEditorWindow.FrameUpdate();
// Test steps.
// ...
}
}