Upgrade NUnit packages to v4 and convert to Assert.That constraint syntax#25374
Upgrade NUnit packages to v4 and convert to Assert.That constraint syntax#25374rolfbjarne wants to merge 22 commits into
Conversation
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.
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.
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.
fa54fde to
0f24c56
Compare
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.
Update all test project files in tests/ to use version properties from the root Directory.Build.props instead of hardcoded versions. This upgrades NUnit from 3.12.0 to 4.4.0, NUnit3TestAdapter from 3.15.1 to 6.1.0, and NUnit.ConsoleRunner from 3.11.1/3.12.0 to 3.22.0. Added NUnitLitePackageVersion and NUnitV2ResultWriterPackageVersion properties to Directory.Build.props for packages that didn't have centralized version properties yet. Also removed stale NUnit.3.11.0 props import from mmptest.csproj. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Convert CollectionAssert to Assert.That constraint syntax in msbuild tests and dotnet UnitTests - Convert Assert.Fail/IsTrue/IsFalse with format args to use string interpolation - Add global using for NUnit.Framework.Legacy in test GlobalUsings.cs to provide CollectionAssert and other classic assertions for monotouch-test and on-device tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
These projects use classic NUnit assertions (Assert.AreEqual, Assert.IsTrue, etc.) which were moved to ClassicAssert in NUnit.Framework.Legacy in NUnit 4. Adding a global using avoids having to convert hundreds of assertion calls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…bility Replace Assert.AreEqual, Assert.AreNotEqual, Assert.IsTrue, Assert.IsFalse, Assert.IsEmpty, Assert.IsNotEmpty with their ClassicAssert equivalents and add using NUnit.Framework.Legacy to each affected file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tro-sharpie Mechanically replace Assert.AreEqual, Assert.IsTrue, Assert.IsFalse, etc. with ClassicAssert equivalents from NUnit.Framework.Legacy for NUnit 4 compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mechanically replace Assert.AreEqual, Assert.IsTrue, Assert.IsFalse, etc. with ClassicAssert equivalents from NUnit.Framework.Legacy for NUnit 4 compatibility in all Xamarin.MacDev.Tasks.Tests and Xamarin.MacDev.Tests source files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fix NUnitLitePackageVersion property ordering in Directory.Build.props. Migrate Assert.X → ClassicAssert.X in monotouch-test, bindings-test, introspection, linker, BundledResources, and EmbeddedResources test files. Convert Assert.Fail/Ignore format-arg calls to string interpolation. Fix nullable reference type warnings in TouchRunner.cs and TestResultElement.cs caused by NUnit 4's improved null annotations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fix F# test, nullable warnings, and CollectionAssert null parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate Assert.X → ClassicAssert.X in bindings-test2, framework-test, interdependent-binding-projects, xcframework-test, fsharp, mtouch, and mmptest test files. Add 'using NUnit.Framework.Legacy' to old-style .NET Framework projects and shared common test files. Fix fully-qualified NUnit.Framework.ClassicAssert → NUnit.Framework.Legacy.ClassicAssert. Fix Assert.Fail format-arg call in MTouch.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NUnit 4 removed format-arg overloads for Assert.Fail and Assert.That. Convert to string.Format and string interpolation respectively. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NLTaggerTest: Convert NSString to string via .ToString() for Assert.That message parameter (NUnit 4 requires string, not NSString). RecordTest: Replace pre-existing StringUtil.StringsEqual calls (StringUtil was never available on iOS) with ClassicAssert.AreEqual. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace all ClassicAssert.X, CollectionAssert.X, and StringAssert.X calls with NUnit v4's Assert.That constraint model across all test projects. Remove all NUnit.Framework.Legacy usings and references. Conversion mappings: - ClassicAssert.AreEqual(exp, act) → Assert.That(act, Is.EqualTo(exp)) - ClassicAssert.IsTrue(x) → Assert.That(x, Is.True) - ClassicAssert.IsNull(x) → Assert.That(x, Is.Null) - ClassicAssert.IsNotNull(x) → Assert.That(x, Is.Not.Null) - ClassicAssert.AreSame(a, b) → Assert.That(b, Is.SameAs(a)) - ClassicAssert.IsInstanceOf<T>(x) → Assert.That(x, Is.InstanceOf<T>()) - CollectionAssert.Contains(c, i) → Assert.That(c, Does.Contain(i)) - StringAssert.Contains(e, a) → Assert.That(a, Does.Contain(e)) - etc. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Re-converted 14 files where the => lambda arrow and >= comparison operator were incorrectly treated as generic type bracket closers, causing Is.True/Is.False/Is.EqualTo to end up inside method call arguments instead of as Assert.That constraint arguments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixed 4 more files where constraint arguments (Is.EqualTo, Is.Not.Null) were incorrectly placed inside nested method calls instead of as Assert.That constraint arguments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rance The conversion script incorrectly treated the 3rd argument of ClassicAssert.AreEqual(expected, actual, message) as a numeric tolerance rather than a message string, producing invalid Is.EqualTo(x).Within(message) instead of Is.EqualTo(x), message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NUnit 4's Assert.That does not support format string arguments after the message parameter. Convert to string interpolation instead. Also simplify ternary expressions that contained string literals which cannot appear inside interpolated string braces. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NUnit 4.4.0 ships nunit.framework.legacy.dll as a transitive dependency, so it appears in app bundles even though we don't use NUnit.Framework.Legacy directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix Is.InstanceOf() conversion: args were swapped (164 occurrences) - Convert testgenerator.cs to emit Assert.That syntax (regenerated code) - Fix broken lambda conversions in IdentityTest.cs and MnistTest.cs - Fix format-arg messages (NUnit 4 doesn't support them) - Fix NLTaggerTest NSString message parameter Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- TrampolineTest: Change tolerance from float to double for NFloat comparisons (NUnit 4 doesn't support float tolerance for NFloat) - MTLIntersectionFunctionTableTests: Add null guard for functionTable which may be null on some hardware - SKTransformNodeTest: Change tolerance from float to double for nfloat comparisons Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The photo library may be empty on the simulator, and SaveToPhotosAlbum is async so re-fetching immediately may still return empty results. Mark as inconclusive instead of crashing with NSRangeException. Also convert Assert.That(bool expr) to proper constraint-based assertions with better failure messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit f010b18.
0f24c56 to
966dae0
Compare
✅ [PR Build #966dae0] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #966dae0] 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 #966dae0] Build passed (Build macOS tests) ✅Pipeline on Agent |
🔥 [CI Build #966dae0] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 52 tests failed, 120 tests passed. Failures❌ fsharp tests2 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)16 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)18 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)6 tests failed, 12 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)5 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests🔥 Failed catastrophically on VSTS: test results - windows (no summary found). Html Report (VSDrops) Download ❌ Tests on macOS Monterey (12) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Ventura (13) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sonoma (14) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sequoia (15) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Tahoe (26) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS testsLinux Build VerificationPipeline on Agent |
Summary
Upgrades all NUnit packages in the tests/ directory to use centralized version properties from Directory.Build.props (NUnit 3.12.0 → 4.4.0, NUnit3TestAdapter → 6.1.0) and converts all test assertions to NUnit v4's proper
Assert.Thatconstraint syntax.Changes
$(NUnitPackageVersion),$(NUnit3TestAdapterPackageVersion), etc. from Directory.Build.propsAssert.AreEqual/Assert.IsTrue/etc. toAssert.That(actual, Is.EqualTo(expected))constraint modelConversion patterns
Assert.AreEqual(expected, actual, msg)Assert.That(actual, Is.EqualTo(expected), msg)Assert.IsTrue(x, msg)Assert.That(x, Is.True, msg)Assert.IsNull(x)Assert.That(x, Is.Null)Assert.Contains(item, collection)Assert.That(collection, Does.Contain(item))CollectionAssert.IsEmpty(x)Assert.That(x, Is.Empty)StringAssert.Contains(sub, str)Assert.That(str, Does.Contain(sub))Verification
cb(clean build) ✅make -C tests build-all✅🤖 Pull request created by Copilot