From a009be96e76908656686759ee1ab050edcc4338d Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 8 Jan 2026 23:33:26 -0800 Subject: [PATCH 1/6] Refactors UI test setup to use TUnit executor Centralizes remote app startup and test recorder management in XamlTestExecutor, removing boilerplate from individual tests; marks long-running tests as explicit and enables TUnit parallel limiting. --- .../MaterialColorUtilities.Tests/HctTests.cs | 2 +- .../MaterialDesignThemes.UITests/AllStyles.cs | 4 - .../MaterialDesignThemes.UITests/TestBase.cs | 22 ++-- .../AutoSuggestTextBoxTests.cs | 35 ------ .../WPF/Buttons/OutlineButtonTests.cs | 13 --- .../WPF/Buttons/RaisedButtonTests.cs | 4 - .../WPF/Cards/ElevatedCardTests.cs | 4 - .../WPF/Cards/OutlinedCardTests.cs | 8 -- .../WPF/ColorPickerTests.cs | 4 - .../WPF/ColorZones/ColorZoneTests.cs | 4 - .../WPF/ComboBoxes/ComboBoxTests.cs | 35 ------ .../ContentControls/ContentControlTests.cs | 4 - .../WPF/DatePickers/DatePickerTests.cs | 35 ------ .../WPF/DialogHosts/DialogHostTests.cs | 52 --------- .../WPF/DrawerHosts/DrawerHostTests.cs | 13 --- .../WPF/Flippers/ClassicFlipperTests.cs | 12 -- .../WPF/ListBoxes/ListBoxTests.cs | 19 ---- .../WPF/PasswordBoxes/PasswordBoxTests.cs | 39 ------- .../WPF/PopupBoxes/PopupBoxTests.cs | 9 -- .../WPF/SnackBars/SnackBarTests.cs | 4 - .../WPF/SplitButtons/SplitButtonTests.cs | 26 +---- .../WPF/TabControls/TabControlTests.cs | 10 -- .../WPF/TextBoxes/TextBoxTests.cs | 81 -------------- .../WPF/TextFieldDefaultHeightTests.cs | 16 --- .../WPF/Theme/ColorAdjustTests.cs | 5 - .../WPF/Theme/ThemeTests.cs | 38 ++++--- .../WPF/TimePickers/TimePickerTests.cs | 87 --------------- .../WPF/ToolBars/ToolBarTests.cs | 4 - .../WPF/TreeListViews/TreeListViewTests.cs | 104 ------------------ .../WPF/TreeViews/TreeViewTests.cs | 10 -- .../WPF/UpDownControls/DecimalUpDownTests.cs | 29 ----- .../WPF/UpDownControls/NumericUpDownTests.cs | 33 ------ .../XamlTestExecutor.cs | 32 ++++++ 33 files changed, 69 insertions(+), 728 deletions(-) create mode 100644 tests/MaterialDesignThemes.UITests/XamlTestExecutor.cs diff --git a/tests/MaterialColorUtilities.Tests/HctTests.cs b/tests/MaterialColorUtilities.Tests/HctTests.cs index 0cd4ed5539..6869be7432 100644 --- a/tests/MaterialColorUtilities.Tests/HctTests.cs +++ b/tests/MaterialColorUtilities.Tests/HctTests.cs @@ -3,7 +3,7 @@ public sealed class HctTests { [Test] - [Skip("Takes a long time to run")] + [Explicit] //Takes a long time to run [DisplayName("HCT preserves original color for all opaque ARGB values")] public async Task Hct_Preserves_Original_Color_For_All_Opaque_ARGB() { diff --git a/tests/MaterialDesignThemes.UITests/AllStyles.cs b/tests/MaterialDesignThemes.UITests/AllStyles.cs index 5d3c6c0f01..cf78a95deb 100644 --- a/tests/MaterialDesignThemes.UITests/AllStyles.cs +++ b/tests/MaterialDesignThemes.UITests/AllStyles.cs @@ -32,8 +32,6 @@ public class AllStyles : TestBase [Arguments("TreeView", "MaterialDesignTreeView")] public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string styleName) { - await using var recorder = new TestRecorder(App); - string applicationResourceXaml = $$""" ] @@ -26,13 +29,16 @@ public record SingleParallelLimit : IParallelLimit public int Limit => 1; } -public abstract class TestBase() +public abstract class TestBase { - protected bool AttachedDebuggerToRemoteProcess { get; set; } = true; + public bool AttachedDebuggerToRemoteProcess { get; set; } = true; protected static TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer"); [NotNull] - protected IApp? App { get; set; } + public IApp? App { get; set; } + + [NotNull] + public TestRecorder? Recorder { get; set; } protected async Task GetThemeColor(string name) { @@ -56,9 +62,9 @@ protected async Task LoadUserControl(Type userControlType) return await App.CreateWindowWithUserControl(userControlType); } - [Before(Test)] - public async ValueTask InitializeAsync() => - App = await XamlTest.App.StartRemote(new AppOptions + public Task StartApp() + { + return XamlTest.App.StartRemote(new AppOptions { #if !DEBUG MinimizeOtherWindows = !System.Diagnostics.Debugger.IsAttached, @@ -66,7 +72,5 @@ public async ValueTask InitializeAsync() => AllowVisualStudioDebuggerAttach = AttachedDebuggerToRemoteProcess, LogMessage = Output.WriteLine }); - - [After(Test)] - public async ValueTask DisposeAsync() => await App.DisposeAsync(); + } } diff --git a/tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs b/tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs index bf6945b564..3d7e72ec24 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs @@ -14,8 +14,6 @@ public AutoSuggestBoxTests() [Test] public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggestions() { - await using var recorder = new TestRecorder(App); - //Arrange IVisualElement suggestBox = (await LoadUserControl()).As(); IVisualElement popup = await suggestBox.GetElement(); @@ -38,15 +36,11 @@ public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggesti await AssertExists(suggestionListBox, "Apples", false); await AssertExists(suggestionListBox, "Mtn Dew", false); await AssertExists(suggestionListBox, "Orange", false); - - recorder.Success(); } [Test] public async Task CanChoiceItem_FromTheSuggestions_AssertTheTextUpdated() { - await using var recorder = new TestRecorder(App); - //Arrange IVisualElement suggestBox = (await LoadUserControl()).As(); IVisualElement popup = await suggestBox.GetElement(); @@ -85,15 +79,11 @@ await Wait.For(async () => var suggestBoxText = await suggestBox.GetText(); //Validate that the current text is the same as the selected item await Assert.That(suggestBoxText).IsEqualTo("Bananas"); - - recorder.Success(); } [Test] public async Task CanFilterItems_WithCollectionView_FiltersSuggestions() { - await using var recorder = new TestRecorder(App); - //Arrange IVisualElement userControl = await LoadUserControl(); IVisualElement suggestBox = await userControl.GetElement(); @@ -117,16 +107,12 @@ public async Task CanFilterItems_WithCollectionView_FiltersSuggestions() await AssertExists(suggestionListBox, "Apples", false); await AssertExists(suggestionListBox, "Mtn Dew", false); await AssertExists(suggestionListBox, "Orange", false); - - recorder.Success(); } [Test] [Description("Issue 3761")] public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed() { - await using var recorder = new TestRecorder(App); - // Arrange string xaml = """ @@ -153,16 +139,12 @@ public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed() // Assert await Assert.That(await suggestBox.GetIsFocused()).IsFalse(); await Assert.That(await nextTextBox.GetIsFocused()).IsTrue(); - - recorder.Success(); } [Test] [Description("Issue 3815")] public async Task AutoSuggestBox_KeysUpAndDown_WrapAround() { - await using var recorder = new TestRecorder(App); - //Arrange IVisualElement suggestBox = (await LoadUserControl()).As(); IVisualElement popup = await suggestBox.GetElement(); @@ -196,16 +178,12 @@ public async Task AutoSuggestBox_KeysUpAndDown_WrapAround() //Assert that the first item is selected after pressing ArrowDown await suggestBox.SendInput(new KeyboardInput(Key.Down)); await Assert.That(await suggestionListBox.GetSelectedIndex()).IsEqualTo(0); - - recorder.Success(); } [Test] [Description("Issue 3845")] public async Task AutoSuggestBox_SelectingAnItem_SetsSelectedItem() { - await using var recorder = new TestRecorder(App); - //Arrange IVisualElement userControl = await LoadUserControl(); IVisualElement suggestBox = await userControl.GetElement(); @@ -228,15 +206,11 @@ static async Task AssertViewModelProperty(AutoSuggestBox autoSuggestBox) await Assert.That(viewModel.SelectedItem).IsEqualTo("Bananas"); } await suggestBox.RemoteExecute(AssertViewModelProperty); - - recorder.Success(); } [Test] public async Task AutoSuggestBox_ClickingButtonInInteractiveItemTemplate_DoesNotSelectOrClosePopup() { - await using var recorder = new TestRecorder(App); - // Arrange IVisualElement suggestBox = (await LoadUserControl()).As(); IVisualElement popup = await suggestBox.GetElement(); @@ -267,14 +241,11 @@ static async Task AssertViewModelProperty(AutoSuggestBox autoSuggestBox) await Assert.That(thirdItem.Count).IsEqualTo(1); } await suggestBox.RemoteExecute(AssertViewModelProperty); - recorder.Success(); } [Test] public async Task AutoSuggestBox_ClickingButtonForcingNonInteractive_SelectsItemAndClosesPopup() { - await using var recorder = new TestRecorder(App); - // Arrange IVisualElement suggestBox = (await LoadUserControl()).As(); IVisualElement popup = await suggestBox.GetElement(); @@ -299,15 +270,11 @@ static void SetNonInteractive(Button button) // Assert await Assert.That(await suggestBox.GetIsSuggestionOpen()).IsFalse(); - - recorder.Success(); } [Test] public async Task AutoSuggestBox_ClickingTextblockThatIsInteractive_DoesNotSelectOrClosePopup() { - await using var recorder = new TestRecorder(App); - // Arrange IVisualElement suggestBox = (await LoadUserControl()).As(); IVisualElement popup = await suggestBox.GetElement(); @@ -336,8 +303,6 @@ static void SetInteractive(TextBlock textBlock) // The list box item should selected because the TextBlock does not handle the click int selectedIndex = await suggestionListBox.GetSelectedIndex(); await Assert.That(selectedIndex).IsEqualTo(2); - - recorder.Success(); } private static async Task AssertExists(IVisualElement suggestionListBox, string text, bool existsOrNotCheck = true) diff --git a/tests/MaterialDesignThemes.UITests/WPF/Buttons/OutlineButtonTests.cs b/tests/MaterialDesignThemes.UITests/WPF/Buttons/OutlineButtonTests.cs index 312ab51d28..9158740a13 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/Buttons/OutlineButtonTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/Buttons/OutlineButtonTests.cs @@ -7,8 +7,6 @@ public class OutlineButtonTests : TestBase [Test] public async Task OutlinedButton_UsesThemeColorForBorder() { - await using var recorder = new TestRecorder(App); - //Arrange IVisualElement