Migrate Xaml.UnitTests from NUnit to xUnit#33012
Conversation
Complete migration of src/Controls/tests/Xaml.UnitTests from NUnit to xUnit testing framework.
2c971b9 to
e69b5a8
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the Controls.Xaml.UnitTests project from NUnit to xUnit testing framework as part of issue #32247. The migration replaces NUnit attributes and assertions with xUnit equivalents while maintaining test functionality. All 1782 tests pass successfully.
Key changes:
- Replaced NUnit test attributes with xUnit equivalents (
[TestFixture]→[Collection],[Test]→[Fact]/[Theory]) - Converted parameterized tests to use
[Theory]with[XamlInflatorData]or[InlineData] - Updated assertions from NUnit syntax to xUnit (
Assert.That()→Assert.Equal(), etc.) - Replaced
[SetUp]/[TearDown]with constructor/IDisposable.Dispose() - Added collection attributes to organize tests and disable parallelization
Reviewed changes
Copilot reviewed 300 out of 412 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Maui25406.xaml.cs | Migrated XamlC compilation test to xUnit with IDisposable pattern |
| Maui25309.xaml.cs | Converted generic converter test using XamlInflatorData |
| Maui25172.xaml.cs | Updated generic base class compilation test |
| Maui25141.xaml.cs | Migrated data trigger and multibinding test |
| Maui24900.xaml.cs | Converted OnPlatform test with Record.Exception pattern |
| Maui24849.xaml.cs | Updated VSG (Visual State Group) test with xUnit assertions |
| Maui24500.xaml.cs | Migrated OnIdiom binding test |
| Maui24472.xaml.cs | Converted x:Array test |
| Maui24384.xaml.cs | Updated immutable collection test |
| Maui2418.rtsg.xaml.cs | Migrated source info test with InlineData for specific inflators |
| Maui23989.xaml.cs | Converted ItemDisplayBinding test with XamlExceptionAssert |
| Maui23711.xaml.cs | Updated binding compilation test |
| Maui23347.xaml.cs | Migrated FontImageSource test |
| Maui23201.xaml.cs | Converted ToolBarItem AppTheme binding test |
| Maui2304Closed.xaml.cs | Updated XamlC test |
| Maui22877.xaml.cs | Migrated OnBinding release test |
| Maui22714.rt.xaml.cs | Converted resource dictionary test with inline data combinations |
| Maui22536.xaml.cs | Updated non-compiled resource dictionary test |
| Maui22105.xaml.cs | Migrated default value test |
| Maui22036.xaml.cs | Converted async style trigger leak test |
| (Additional files) | Similar xUnit migration patterns applied across 100+ test files |
| [Test] | ||
| public void VerifyCorrectTypesUsed([Values] XamlInflator inflator) | ||
| [Theory] | ||
| [InlineData(XamlInflator.Runtime)] |
There was a problem hiding this comment.
Could this use XamlInflatorData ?
rmarinho
left a comment
There was a problem hiding this comment.
Did n t saw nothing bad, maybe just some exceptions where we check the lines, I wonder if we can use XamlExceptionAssert.ThrowsBuildException , but looks good to merge
| else if (inflator == XamlInflator.Runtime) | ||
| Assert.Throws(new XamlParseExceptionConstraint(9, 6), () => new Bz43694(inflator)); | ||
| { | ||
| var ex = Assert.ThrowsAny<Exception>(() => new Bz43694(inflator)); |
There was a problem hiding this comment.
Do we need a way to check the line is correct here?
| Assert.Single(result.Diagnostics); | ||
| } | ||
| else | ||
| Assert.Ignore($"Test not supported for {inflator}"); |
There was a problem hiding this comment.
We lost this one , but I think is fine.
| @@ -46,7 +47,7 @@ public partial class Gh4751 : ContentPage | |||
| """) | |||
| .RunMauiSourceGenerator(typeof(Gh4751)); | |||
| //FIXME check the diagnostic code | |||
| @@ -34,10 +35,8 @@ public partial class Gh5378_1 : ContentPage | |||
| """) | |||
| .RunMauiSourceGenerator(typeof(Gh5378_1)); | |||
| //FIXME check diagnostic code | |||
| @@ -34,10 +35,10 @@ public partial class Gh7187 : ContentPage | |||
| """) | |||
| .RunMauiSourceGenerator(typeof(Gh7187)); | |||
| //FIXME check diagnostic code | |||
| @@ -218,7 +219,6 @@ public void Issue1493(string culture) | |||
| cmp:RelativeLayout.WidthConstraint=""{cmp:ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.6}""/>"; | |||
| View view = new View(); | |||
| view.LoadFromXaml(xaml); | |||
- Bz43694, Bz44216, Issue2450: Use XamlExceptionAssert to check exception line/position and message content - Maui17222: Replace IDisposable with try/finally for cleanup
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
This PR migrates the
Controls.Xaml.UnitTestsproject from NUnit to xUnit, as part of the effort tracked in #32247.Changes
Test Framework Migration
[TestFixture]with xUnit[Collection]attributes[Test]to[Theory]with[MemberData]for parameterized tests[Values]attribute pattern withXamlInflatorTestDatamember data providerAssert.That()/Assert.AreEqual()to xUnitAssert.Equal()/Assert.NotNull()etc.[SetUp]/[TearDown]with xUnit constructor /IDisposable.Dispose()patternAssert.Throws<T>/Assert.DoesNotThrowwith xUnit equivalentsTest Organization
[Collection("Xaml Inflation")][Collection("Issue")]DisableParallelization = trueto maintain test isolationInfrastructure
XamlInflatorTestDataclass providingIEnumerable<object[]>for inflator variationsTest Results
All 1782 tests passing (same count as main branch).
Fixes #32247