[tests] Upgrade tests/dotnet to NUnit v4 Assert.That syntax#25487
Conversation
Migrate all classic assertions (AreEqual, IsTrue, IsNull, etc.) to Assert.That constraint syntax in tests/dotnet/UnitTests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the tests/dotnet/UnitTests suite to use NUnit v4-style Assert.That constraint-based assertions, aligning the unit tests with the newer NUnit assertion idioms.
Changes:
- Migrated classic assertions (
AreEqual,IsTrue,Contains, etc.) toAssert.That(..., <constraint>)acrosstests/dotnet/UnitTests. - Updated the UnitTests project to use centralized NUnit package version properties.
- Adjusted bundle structure expectations for the additional NUnit legacy framework assembly.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/dotnet/UnitTests/XcodeProjectTests.cs | Converted collection/string assertions to constraint-based equivalents. |
| tests/dotnet/UnitTests/WindowsTest.cs | Converted null/value assertions to Assert.That constraints. |
| tests/dotnet/UnitTests/TestBaseClass.cs | Converted exit-code assertions to constraint syntax. |
| tests/dotnet/UnitTests/TemplateTest.cs | Converted execution and inequality assertions to constraints. |
| tests/dotnet/UnitTests/TemplateProjectTest.cs | Converted error count/message assertions to constraints. |
| tests/dotnet/UnitTests/ResourcePrefixTest.cs | Converted equality assertions to constraints across platform variations. |
| tests/dotnet/UnitTests/RegistrarTest.cs | Converted validation assertions to constraint syntax. |
| tests/dotnet/UnitTests/PublishTrimmedTest.cs | Converted error count/message assertions to constraints. |
| tests/dotnet/UnitTests/ProjectTest.cs | Converted many Info.plist, warning/error, and collection assertions to constraints. |
| tests/dotnet/UnitTests/PostBuildTest.cs | Converted publish-failure assertions to constraints. |
| tests/dotnet/UnitTests/PartialAppManifestTest.cs | Converted Info.plist assertions to constraint syntax. |
| tests/dotnet/UnitTests/PackTest.cs | Converted collection/equality assertions (including ordered sequences) to constraints. |
| tests/dotnet/UnitTests/MlaunchTest.cs | Converted argument/script content assertions to constraints. |
| tests/dotnet/UnitTests/MauiTest.cs | Converted Info.plist and binlog property assertions to constraints. |
| tests/dotnet/UnitTests/Extensions.cs | Updated inline guidance comment to reference Assert.That(..., Is.Empty) usage. |
| tests/dotnet/UnitTests/DotNetUnitTests.csproj | Switched NUnit/TestAdapter references to centralized version properties. |
| tests/dotnet/UnitTests/BundleStructureTest.cs | Updated expected bundle contents and converted collection assertions to constraints. |
| tests/dotnet/UnitTests/AssetsTest.cs | Converted null/collection/comparison assertions to constraints. |
| tests/dotnet/UnitTests/AppIconTest.cs | Converted null/collection assertions to constraints. |
| Assert.That (warnings.Length, Is.EqualTo (1), "Warning count"); | ||
| Assert.That ("IL2075", Is.EqualTo (warnings [0].Code), "Warning code"); | ||
| Assert.That ("'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", Is.EqualTo (warnings [0].Message)); |
| <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> | ||
| <PackageReference Include="NUnit" Version="$(NUnitPackageVersion)" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="$(NUnit3TestAdapterPackageVersion)" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" /> |
| @@ -377,7 +377,7 @@ public void RemoteTest (ApplePlatform platform, string runtimeIdentifiers) | |||
| using var zip = ZipFile.OpenRead (zippedAppBundlePath); | |||
| ZipHelpers.DumpZipFile (zip, zippedAppBundlePath); | |||
| var infoPlistEntry = zip.Entries.SingleOrDefault (v => v.Name == "Info.plist")!; | |||
| Assert.That (expectedXcodeFxOutput, Does.Exist, $"Expected xcframework output '{expectedXcodeFxOutput}' did not exist."); | ||
| var outputFxThirdWriteTime = File.GetLastWriteTime (expectedXcodeFxOutput); | ||
| Assert.IsTrue (outputFxThirdWriteTime > outputFxFirstWriteTime, $"Expected '{outputFxThirdWriteTime}' write time of '{outputFxThirdWriteTime}' to be greater than first write '{outputFxFirstWriteTime}'"); | ||
| Assert.That (outputFxThirdWriteTime > outputFxFirstWriteTime, Is.True, $"Expected '{outputFxThirdWriteTime}' write time of '{outputFxThirdWriteTime}' to be greater than first write '{outputFxFirstWriteTime}'"); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Remove nunit.framework.legacy.dll from expected bundle files (the BundleStructure test project doesn't reference it) - Use centralized MicrosoftNETTestSdkPackageVersion property - Fix reversed actual/expected in Assert.That calls (ProjectTest.cs) - Add explicit null assertions before null-forgiving dereferences - Remove redundant null-forgiving operator on SingleOrDefault - Use Is.GreaterThan constraint instead of boolean comparison Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #ec40ca0] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #ec40ca0] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [PR Build #ec40ca0] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #ec40ca0] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 183 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Migrate all classic assertions (AreEqual, IsTrue, IsNull, etc.) to
Assert.That constraint syntax in tests/dotnet/UnitTests.