Skip to content

[tests] Upgrade tests/dotnet to NUnit v4 Assert.That syntax#25487

Merged
rolfbjarne merged 3 commits into
mainfrom
dev/rolf/nunitv4-dotnet
May 21, 2026
Merged

[tests] Upgrade tests/dotnet to NUnit v4 Assert.That syntax#25487
rolfbjarne merged 3 commits into
mainfrom
dev/rolf/nunitv4-dotnet

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

Migrate all classic assertions (AreEqual, IsTrue, IsNull, etc.) to
Assert.That constraint syntax in tests/dotnet/UnitTests.

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>
Copy link
Copy Markdown
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 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.) to Assert.That(..., <constraint>) across tests/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.

Comment thread tests/dotnet/UnitTests/ProjectTest.cs Outdated
Comment on lines +2538 to +2540
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" />
Comment thread tests/dotnet/UnitTests/WindowsTest.cs Outdated
@@ -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}'");
Comment thread tests/dotnet/UnitTests/ProjectTest.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits May 21, 2026 09:14
- 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>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne marked this pull request as ready for review May 21, 2026 14:08
@rolfbjarne rolfbjarne enabled auto-merge (squash) May 21, 2026 14:08
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #ec40ca0] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: ec40ca0867b5ebbd6b11668082acfcf0fa22113d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #ec40ca0] Build passed (Build packages) ✅

Pipeline on Agent
Hash: ec40ca0867b5ebbd6b11668082acfcf0fa22113d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: ec40ca0867b5ebbd6b11668082acfcf0fa22113d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #ec40ca0] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: ec40ca0867b5ebbd6b11668082acfcf0fa22113d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [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
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (iOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ monotouch (macOS): All 20 tests passed. [attempt 2] (⚠️ Html Report Publish failed ⚠️) Download
✅ monotouch (tvOS): All 18 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: ec40ca0867b5ebbd6b11668082acfcf0fa22113d [PR build]

@rolfbjarne rolfbjarne merged commit a3720d3 into main May 21, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants