Skip to content

Commit a009be9

Browse files
committed
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.
1 parent 5ee1c9d commit a009be9

33 files changed

Lines changed: 69 additions & 728 deletions

tests/MaterialColorUtilities.Tests/HctTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public sealed class HctTests
44
{
55
[Test]
6-
[Skip("Takes a long time to run")]
6+
[Explicit] //Takes a long time to run
77
[DisplayName("HCT preserves original color for all opaque ARGB values")]
88
public async Task Hct_Preserves_Original_Color_For_All_Opaque_ARGB()
99
{

tests/MaterialDesignThemes.UITests/AllStyles.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public class AllStyles : TestBase
3232
[Arguments("TreeView", "MaterialDesignTreeView")]
3333
public async Task LoadStyleInIsolation_CanBeLoaded(string controlName, string styleName)
3434
{
35-
await using var recorder = new TestRecorder(App);
36-
3735
string applicationResourceXaml = $$"""
3836
<ResourceDictionary
3937
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -78,7 +76,5 @@ await App.Initialize(applicationResourceXaml,
7876
""");
7977

8078
await Assert.That(await window.GetIsVisible()).IsTrue();
81-
82-
recorder.Success();
8379
}
8480
}

tests/MaterialDesignThemes.UITests/TestBase.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using System.Windows.Media;
33
using MaterialDesignThemes.UITests;
44
using MaterialDesignThemes.Wpf.Internal;
5+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
6+
using Microsoft.VisualStudio.TestPlatform.Utilities;
7+
using TUnit.Core;
58
using TUnit.Core.Interfaces;
69

710
[assembly: ParallelLimiter<SingleParallelLimit>]
@@ -26,13 +29,16 @@ public record SingleParallelLimit : IParallelLimit
2629
public int Limit => 1;
2730
}
2831

29-
public abstract class TestBase()
32+
public abstract class TestBase
3033
{
31-
protected bool AttachedDebuggerToRemoteProcess { get; set; } = true;
34+
public bool AttachedDebuggerToRemoteProcess { get; set; } = true;
3235
protected static TextWriter Output => TestContext.Current?.OutputWriter ?? throw new InvalidOperationException("Could not find output writer");
3336

3437
[NotNull]
35-
protected IApp? App { get; set; }
38+
public IApp? App { get; set; }
39+
40+
[NotNull]
41+
public TestRecorder? Recorder { get; set; }
3642

3743
protected async Task<Color> GetThemeColor(string name)
3844
{
@@ -56,17 +62,15 @@ protected async Task<IVisualElement> LoadUserControl(Type userControlType)
5662
return await App.CreateWindowWithUserControl(userControlType);
5763
}
5864

59-
[Before(Test)]
60-
public async ValueTask InitializeAsync() =>
61-
App = await XamlTest.App.StartRemote(new AppOptions
65+
public Task<IApp> StartApp()
66+
{
67+
return XamlTest.App.StartRemote(new AppOptions
6268
{
6369
#if !DEBUG
6470
MinimizeOtherWindows = !System.Diagnostics.Debugger.IsAttached,
6571
#endif
6672
AllowVisualStudioDebuggerAttach = AttachedDebuggerToRemoteProcess,
6773
LogMessage = Output.WriteLine
6874
});
69-
70-
[After(Test)]
71-
public async ValueTask DisposeAsync() => await App.DisposeAsync();
75+
}
7276
}

tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public AutoSuggestBoxTests()
1414
[Test]
1515
public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggestions()
1616
{
17-
await using var recorder = new TestRecorder(App);
18-
1917
//Arrange
2018
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithTemplate>()).As<AutoSuggestBox>();
2119
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -38,15 +36,11 @@ public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggesti
3836
await AssertExists(suggestionListBox, "Apples", false);
3937
await AssertExists(suggestionListBox, "Mtn Dew", false);
4038
await AssertExists(suggestionListBox, "Orange", false);
41-
42-
recorder.Success();
4339
}
4440

4541
[Test]
4642
public async Task CanChoiceItem_FromTheSuggestions_AssertTheTextUpdated()
4743
{
48-
await using var recorder = new TestRecorder(App);
49-
5044
//Arrange
5145
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithTemplate>()).As<AutoSuggestBox>();
5246
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -85,15 +79,11 @@ await Wait.For(async () =>
8579
var suggestBoxText = await suggestBox.GetText();
8680
//Validate that the current text is the same as the selected item
8781
await Assert.That(suggestBoxText).IsEqualTo("Bananas");
88-
89-
recorder.Success();
9082
}
9183

9284
[Test]
9385
public async Task CanFilterItems_WithCollectionView_FiltersSuggestions()
9486
{
95-
await using var recorder = new TestRecorder(App);
96-
9787
//Arrange
9888
IVisualElement userControl = await LoadUserControl<AutoSuggestTextBoxWithCollectionView>();
9989
IVisualElement<AutoSuggestBox> suggestBox = await userControl.GetElement<AutoSuggestBox>();
@@ -117,16 +107,12 @@ public async Task CanFilterItems_WithCollectionView_FiltersSuggestions()
117107
await AssertExists(suggestionListBox, "Apples", false);
118108
await AssertExists(suggestionListBox, "Mtn Dew", false);
119109
await AssertExists(suggestionListBox, "Orange", false);
120-
121-
recorder.Success();
122110
}
123111

124112
[Test]
125113
[Description("Issue 3761")]
126114
public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed()
127115
{
128-
await using var recorder = new TestRecorder(App);
129-
130116
// Arrange
131117
string xaml = """
132118
<StackPanel>
@@ -153,16 +139,12 @@ public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed()
153139
// Assert
154140
await Assert.That(await suggestBox.GetIsFocused()).IsFalse();
155141
await Assert.That(await nextTextBox.GetIsFocused()).IsTrue();
156-
157-
recorder.Success();
158142
}
159143

160144
[Test]
161145
[Description("Issue 3815")]
162146
public async Task AutoSuggestBox_KeysUpAndDown_WrapAround()
163147
{
164-
await using var recorder = new TestRecorder(App);
165-
166148
//Arrange
167149
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithTemplate>()).As<AutoSuggestBox>();
168150
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -196,16 +178,12 @@ public async Task AutoSuggestBox_KeysUpAndDown_WrapAround()
196178
//Assert that the first item is selected after pressing ArrowDown
197179
await suggestBox.SendInput(new KeyboardInput(Key.Down));
198180
await Assert.That(await suggestionListBox.GetSelectedIndex()).IsEqualTo(0);
199-
200-
recorder.Success();
201181
}
202182

203183
[Test]
204184
[Description("Issue 3845")]
205185
public async Task AutoSuggestBox_SelectingAnItem_SetsSelectedItem()
206186
{
207-
await using var recorder = new TestRecorder(App);
208-
209187
//Arrange
210188
IVisualElement userControl = await LoadUserControl<AutoSuggestTextBoxWithCollectionView>();
211189
IVisualElement<AutoSuggestBox> suggestBox = await userControl.GetElement<AutoSuggestBox>();
@@ -228,15 +206,11 @@ static async Task AssertViewModelProperty(AutoSuggestBox autoSuggestBox)
228206
await Assert.That(viewModel.SelectedItem).IsEqualTo("Bananas");
229207
}
230208
await suggestBox.RemoteExecute(AssertViewModelProperty);
231-
232-
recorder.Success();
233209
}
234210

235211
[Test]
236212
public async Task AutoSuggestBox_ClickingButtonInInteractiveItemTemplate_DoesNotSelectOrClosePopup()
237213
{
238-
await using var recorder = new TestRecorder(App);
239-
240214
// Arrange
241215
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithInteractiveTemplate>()).As<AutoSuggestBox>();
242216
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -267,14 +241,11 @@ static async Task AssertViewModelProperty(AutoSuggestBox autoSuggestBox)
267241
await Assert.That(thirdItem.Count).IsEqualTo(1);
268242
}
269243
await suggestBox.RemoteExecute(AssertViewModelProperty);
270-
recorder.Success();
271244
}
272245

273246
[Test]
274247
public async Task AutoSuggestBox_ClickingButtonForcingNonInteractive_SelectsItemAndClosesPopup()
275248
{
276-
await using var recorder = new TestRecorder(App);
277-
278249
// Arrange
279250
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithInteractiveTemplate>()).As<AutoSuggestBox>();
280251
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -299,15 +270,11 @@ static void SetNonInteractive(Button button)
299270

300271
// Assert
301272
await Assert.That(await suggestBox.GetIsSuggestionOpen()).IsFalse();
302-
303-
recorder.Success();
304273
}
305274

306275
[Test]
307276
public async Task AutoSuggestBox_ClickingTextblockThatIsInteractive_DoesNotSelectOrClosePopup()
308277
{
309-
await using var recorder = new TestRecorder(App);
310-
311278
// Arrange
312279
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithInteractiveTemplate>()).As<AutoSuggestBox>();
313280
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
@@ -336,8 +303,6 @@ static void SetInteractive(TextBlock textBlock)
336303
// The list box item should selected because the TextBlock does not handle the click
337304
int selectedIndex = await suggestionListBox.GetSelectedIndex();
338305
await Assert.That(selectedIndex).IsEqualTo(2);
339-
340-
recorder.Success();
341306
}
342307

343308
private static async Task AssertExists(IVisualElement<ListBox> suggestionListBox, string text, bool existsOrNotCheck = true)

tests/MaterialDesignThemes.UITests/WPF/Buttons/OutlineButtonTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public class OutlineButtonTests : TestBase
77
[Test]
88
public async Task OutlinedButton_UsesThemeColorForBorder()
99
{
10-
await using var recorder = new TestRecorder(App);
11-
1210
//Arrange
1311
IVisualElement<Button> button = await LoadXaml<Button>(
1412
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
@@ -22,23 +20,18 @@ public async Task OutlinedButton_UsesThemeColorForBorder()
2220
//Assert
2321
await Assert.That(borderColor).IsEqualTo(midColor);
2422
await Assert.That(internalBorderColor).IsEqualTo(midColor);
25-
26-
recorder.Success();
2723
}
2824

2925
[Test]
3026
public async Task OutlinedButton_BorderCanBeOverridden()
3127
{
32-
await using var recorder = new TestRecorder(App);
33-
3428
//Arrange
3529
var button = await LoadXaml<Button>(
3630
@"<Button Content=""Button""
3731
Style=""{StaticResource MaterialDesignOutlinedButton}""
3832
BorderThickness=""5""
3933
BorderBrush=""Red""
4034
/>");
41-
Color midColor = await GetThemeColor("MaterialDesign.Brush.Primary");
4235
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
4336

4437
//Act
@@ -48,15 +41,11 @@ public async Task OutlinedButton_BorderCanBeOverridden()
4841
//Assert
4942
await Assert.That(borderThickness).IsEqualTo(new Thickness(5));
5043
await Assert.That(borderBrush).IsEqualTo(Colors.Red);
51-
52-
recorder.Success();
5344
}
5445

5546
[Test]
5647
public async Task OutlinedButton_OnMouseOver_UsesThemeBrush()
5748
{
58-
await using var recorder = new TestRecorder(App);
59-
6049
//Arrange
6150
IVisualElement<Button> button = await LoadXaml<Button>(
6251
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
@@ -72,7 +61,5 @@ await Wait.For(async () =>
7261
//Assert
7362
await Assert.That(internalBorderBackground?.Color).IsEqualTo(midColor);
7463
});
75-
76-
recorder.Success();
7764
}
7865
}

tests/MaterialDesignThemes.UITests/WPF/Buttons/RaisedButtonTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public class RaisedButtonTests : TestBase
77
[Test]
88
public async Task OnLoad_ThemeBrushesSet()
99
{
10-
await using var recorder = new TestRecorder(App);
11-
1210
//Arrange
1311
IVisualElement<Button> button = await LoadXaml<Button>(@"<Button Content=""Button"" />");
1412
Color midColor = await GetThemeColor("MaterialDesign.Brush.Primary");
@@ -18,7 +16,5 @@ public async Task OnLoad_ThemeBrushesSet()
1816

1917
//Assert
2018
await Assert.That(color).IsEqualTo(midColor);
21-
22-
recorder.Success();
2319
}
2420
}

tests/MaterialDesignThemes.UITests/WPF/Cards/ElevatedCardTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ public class ElevatedCardTests : TestBase
88
[Test]
99
public async Task ElevatedCard_UniformCornerRadiusApplied_AppliesCornerRadiusOnBorder()
1010
{
11-
await using var recorder = new TestRecorder(App);
12-
1311
//Arrange
1412
IVisualElement<Card> card = await LoadXaml<Card>(
1513
@"<materialDesign:Card Content=""Hello World"" Style=""{StaticResource MaterialDesignElevatedCard}"" UniformCornerRadius=""5"" />");
@@ -23,7 +21,5 @@ public async Task ElevatedCard_UniformCornerRadiusApplied_AppliesCornerRadiusOnB
2321
await Assert.That(internalBorderCornerRadius.Value.TopRight).IsEqualTo(5);
2422
await Assert.That(internalBorderCornerRadius.Value.BottomRight).IsEqualTo(5);
2523
await Assert.That(internalBorderCornerRadius.Value.BottomLeft).IsEqualTo(5);
26-
27-
recorder.Success();
2824
}
2925
}

tests/MaterialDesignThemes.UITests/WPF/Cards/OutlinedCardTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public class OutlinedCardTests : TestBase
77
[Test]
88
public async Task OutlinedCard_UsesThemeColorForBorder()
99
{
10-
await using var recorder = new TestRecorder(App);
11-
1210
//Arrange
1311
IVisualElement<Card> card = await LoadXaml<Card>(
1412
@"<materialDesign:Card Content=""Hello World"" Style=""{StaticResource MaterialDesignOutlinedCard}""/>");
@@ -20,15 +18,11 @@ public async Task OutlinedCard_UsesThemeColorForBorder()
2018

2119
//Assert
2220
await Assert.That(internalBorderColor).IsEqualTo(dividerColor);
23-
24-
recorder.Success();
2521
}
2622

2723
[Test]
2824
public async Task OutlinedCard_UniformCornerRadiusApplied_AppliesCornerRadiusOnBorder()
2925
{
30-
await using var recorder = new TestRecorder(App);
31-
3226
//Arrange
3327
IVisualElement<Card> card = await LoadXaml<Card>(
3428
@"<materialDesign:Card Content=""Hello World"" Style=""{StaticResource MaterialDesignOutlinedCard}"" UniformCornerRadius=""5"" />");
@@ -42,7 +36,5 @@ public async Task OutlinedCard_UniformCornerRadiusApplied_AppliesCornerRadiusOnB
4236
await Assert.That(internalBorderCornerRadius.Value.TopRight).IsEqualTo(5);
4337
await Assert.That(internalBorderCornerRadius.Value.BottomRight).IsEqualTo(5);
4438
await Assert.That(internalBorderCornerRadius.Value.BottomLeft).IsEqualTo(5);
45-
46-
recorder.Success();
4739
}
4840
}

tests/MaterialDesignThemes.UITests/WPF/ColorPickerTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ public class ColorPickerTests : TestBase
88
[Test]
99
public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday()
1010
{
11-
await using var recorder = new TestRecorder(App);
12-
1311
IVisualElement<ColorPicker> colorPicker = await LoadXaml<ColorPicker>(@"
1412
<materialDesign:ColorPicker Width=""400"" Height=""100"" Color=""Red""/>");
1513

@@ -30,7 +28,5 @@ public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday()
3028

3129
double currentBrightness = (await colorPicker.GetColor()).ToHsb().Brightness;
3230
await Assert.That(currentBrightness).IsLessThan(lastBrightness);
33-
34-
recorder.Success();
3531
}
3632
}

tests/MaterialDesignThemes.UITests/WPF/ColorZones/ColorZoneTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public class ColorZoneTests : TestBase
1818
[Arguments(ColorZoneMode.Dark, "MaterialDesign.Brush.ColorZone.DarkBackground", "MaterialDesign.Brush.ColorZone.DarkForeground")]
1919
public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrush, string foregroundBrush)
2020
{
21-
await using var recorder = new TestRecorder(App);
22-
2321
IVisualElement<ColorZone> colorZone = await LoadXaml<ColorZone>(@$"
2422
<materialDesign:ColorZone Mode=""{mode}""/>
2523
");
@@ -28,7 +26,5 @@ public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrus
2826

2927
await Assert.That(await colorZone.GetBackgroundColor()).IsEqualTo(background);
3028
await Assert.That(await colorZone.GetForegroundColor()).IsEqualTo(foreground);
31-
32-
recorder.Success();
3329
}
3430
}

0 commit comments

Comments
 (0)