Skip to content

Conversation

@StephaneDelcroix
Copy link
Contributor

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.UnitTests project from NUnit to xUnit, as part of the effort tracked in #32247.

Changes

Test Framework Migration

  • Replaced NUnit [TestFixture] with xUnit [Collection] attributes
  • Converted [Test] to [Theory] with [MemberData] for parameterized tests
  • Replaced [Values] attribute pattern with XamlInflatorTestData member data provider
  • Updated assertions from NUnit Assert.That() / Assert.AreEqual() to xUnit Assert.Equal() / Assert.NotNull() etc.
  • Replaced [SetUp] / [TearDown] with xUnit constructor / IDisposable.Dispose() pattern
  • Replaced Assert.Throws<T> / Assert.DoesNotThrow with xUnit equivalents

Test Organization

  • Tests in root folder use [Collection("Xaml Inflation")]
  • Tests in Issues/ folder use [Collection("Issue")]
  • Added collection definitions with DisableParallelization = true to maintain test isolation

Infrastructure

  • Added XamlInflatorTestData class providing IEnumerable<object[]> for inflator variations
  • Removed NUnit package references
  • Removed dead code (XamlgTests.cs - was entirely commented out)

Test Results

All 1782 tests passing (same count as main branch).

Fixes #32247

Complete migration of src/Controls/tests/Xaml.UnitTests from NUnit to xUnit testing framework.
@StephaneDelcroix StephaneDelcroix force-pushed the feature/xaml-unittests-xunit-migration-32247 branch from 2c971b9 to e69b5a8 Compare December 5, 2025 11:38
@StephaneDelcroix StephaneDelcroix marked this pull request as ready for review December 5, 2025 11:38
Copilot AI review requested due to automatic review settings December 5, 2025 11:38
Copy link
Contributor

Copilot AI left a 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 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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use XamlInflatorData ?

rmarinho
rmarinho previously approved these changes Dec 5, 2025
Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a way to check the line is correct here?

Assert.Single(result.Diagnostics);
}
else
Assert.Ignore($"Test not supported for {inflator}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost this one , but I think is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is fine

}
""")
.RunMauiSourceGenerator(typeof(Gh4751));
//FIXME check the diagnostic code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix it now?

}
""")
.RunMauiSourceGenerator(typeof(Gh5378_1));
//FIXME check diagnostic code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we fix it ?

""")
.RunMauiSourceGenerator(typeof(Gh7187));
//FIXME check diagnostic code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check the code now ?

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO we need to use the Record.

- Bz43694, Bz44216, Issue2450: Use XamlExceptionAssert to check
  exception line/position and message content
- Maui17222: Replace IDisposable with try/finally for cleanup
@rmarinho rmarinho merged commit 36cd96a into main Dec 6, 2025
155 of 163 checks passed
@rmarinho rmarinho deleted the feature/xaml-unittests-xunit-migration-32247 branch December 6, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Controls.Xaml.UnitTests from NUnit to xUnit

3 participants