-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[testing] Refactor Xaml unit tests to Xunit #32446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors XAML unit tests from NUnit to xUnit, migrating test attributes, assertion syntax, and test lifecycle management across numerous test files in the Controls.Xaml.UnitTests project.
Key Changes
- Converted NUnit test attributes ([Test], [TestFixture], [SetUp], [TearDown]) to xUnit equivalents ([Fact], [Theory], constructor, IDisposable)
- Replaced NUnit assertions with xUnit assertion syntax (e.g., Assert.That → Assert.Equal)
- Updated test class visibility from internal to public to meet xUnit requirements
- Added System namespace imports and removed NUnit.Framework references
Reviewed Changes
Copilot reviewed 300 out of 403 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| Maui24900.xaml.cs | Converted test class to xUnit with constructor setup and Dispose method; left incomplete test with TODO comment |
| Maui24849.xaml.cs | Migrated NUnit assertions to xUnit equivalents; changed Color.FromHex usage with TODO note |
| Maui24500.xaml.cs | Updated test structure to xUnit Theory with Values attribute |
| Maui23989.xaml.cs | Converted BuildException verification with TODO for detailed exception validation |
| Maui23711.xaml.cs | Migrated assertions and test lifecycle to xUnit patterns |
| Maui2418.rtsg.xaml.cs | Added IDisposable implementation; converted InlineData usage for XamlInflator values |
| Multiple Issue files | Systematic conversion of test attributes, assertions, and class structure across 100+ test files |
Comments suppressed due to low confidence (1)
src/Controls/tests/Xaml.UnitTests/Issues/Gh7097.xaml.cs:1
- The test method is decorated with [Fact] but accepts a parameter (XamlInflator inflator). [Fact] tests cannot have parameters. This should use [Theory] with appropriate data attributes like [Values] or [InlineData].
using System;
| [Theory] | ||
| [Values] | ||
| public void OnPlatformDoesNotThrow() |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method is decorated with [Theory] and [Values] but has no parameters. This test will fail at runtime. The method signature should include XamlInflator inflator parameter to match the [Values] attribute usage pattern seen throughout the codebase.
| Assert.That(page.button.IsEnabled, Is.False); | ||
| Assert.That(page.button.TextColor, Is.EqualTo(Color.FromHex("#3c3c3b"))); | ||
| Assert.False(page.button.IsEnabled); | ||
| Assert.Equal(Color.FromArgb("#3c3c3b"), page.button.TextColor); // TODO: Was FromHex with 2 params, added actual value |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color.FromArgb expects a color in ARGB format but is being passed a hex string that appears to be RGB only (6 characters after #). This should either use Color.FromRgb or the hex string should be prefixed with 'FF' to make it a valid ARGB value.
| var page = new Maui24384(inflator); | ||
| var picker = page.Content as Picker; | ||
| Assert.That(picker.ItemsSource, Is.EquivalentTo(Maui24384.StaticLetters)); | ||
| Assert.Equal(Maui24384.StaticLetters, picker.ItemsSource); // TODO: Was Assert.EquivalentTo |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert.Equal checks for reference equality or exact sequence equality, but the original NUnit Assert.EquivalentTo checked for content equivalence regardless of order. This should use Assert.Equivalent or Assert.Equal with a comparer to maintain the original test behavior.
| { | ||
| Console.WriteLine("event called"); | ||
| Assert.Pass(); | ||
| // TODO: XUnit has no // TODO: XUnit has no Assert.Pass() - test passes if no exception is thrown - test passes if no exception is thrown |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated TODO comment text ('XUnit has no' appears twice). The comment should be simplified to: '// In xUnit, test passes if no exception is thrown'.
| // TODO: XUnit has no // TODO: XUnit has no Assert.Pass() - test passes if no exception is thrown - test passes if no exception is thrown | |
| // In xUnit, test passes if no exception is thrown |
| // TODO: XUnit doesn't have Assert.Fail, use Assert.True(false, ...) or throw | ||
| throw new InvalidOperationException("no method invoked"); |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects an exception to be thrown from button.SendClicked() but instead throws unconditionally after the call. The throw statement should be inside a catch block or the test logic should verify that SendClicked invokes the correct TestBtn overload and throws from there.
| public void BindingToEmptyCollection([Values] XamlInflator inflator) | ||
| [Theory] | ||
| [Values] | ||
| public void BindingToEmptyCollection() |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method signature is missing the XamlInflator inflator parameter but is decorated with [Theory] and [Values]. This will cause a runtime error. Add the inflator parameter and use it in the test method body.
| public void BindingThrowsOnWrongConverterParameter([Values] XamlInflator inflator) | ||
| [Theory] | ||
| [Values] | ||
| public void BindingThrowsOnWrongConverterParameter() |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method is decorated with [Theory] and [Values] but lacks the XamlInflator inflator parameter. Add the parameter to match the attribute usage pattern.
| public void BindingThrowsOnWrongConverterParameter() | |
| public void BindingThrowsOnWrongConverterParameter(XamlInflator inflator) |
| public void RectangleGeometryDoesntThrow([Values] XamlInflator inflator) => Assert.DoesNotThrow(() => new Gh11541(inflator)); | ||
| [Theory] | ||
| [Values] | ||
| public void RectangleGeometryDoesntThrow() |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method is decorated with [Theory] and [Values] but is missing the XamlInflator inflator parameter. This will fail at runtime.
| { | ||
| DispatcherProvider.SetCurrent(null); | ||
| } |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation in the Dispose method. The method body uses spaces instead of tabs, differing from the surrounding code style. Normalize to match the project's indentation style.
Description of Change
Used copilot to move XAML unit tests to Xunit