Skip to content

[tests] Upgrade tests/introspection to NUnit v4 Assert.That syntax - #25442

Merged
rolfbjarne merged 1 commit into
mainfrom
dev/rolf/nunitv4-introspection
May 18, 2026
Merged

rolfbjarne merged 1 commit into
mainfrom
dev/rolf/nunitv4-introspection

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Convert classic NUnit assertions to NUnit v4's constraint-based
Assert.That syntax in the introspection test project.

Convert classic NUnit assertions to NUnit v4's constraint-based
Assert.That syntax in the introspection test project.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 15, 2026 10:58
@rolfbjarne
rolfbjarne enabled auto-merge (squash) May 15, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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/introspection NUnit assertions to use NUnit v4’s constraint-based Assert.That style, keeping the introspection test suite aligned with newer NUnit APIs and patterns.

Changes:

  • Converted multiple classic NUnit assertions (Assert.AreEqual/True/IsFalse/Null/...) to Assert.That constraints across the introspection tests.
  • Adjusted some assertion failure messages to use interpolated strings.
  • Added "Ppd" to the allowed typo list for macOS to avoid false positives for the PPD acronym.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/introspection/ApiWeakPropertyTest.cs Converted final error count assertion to Assert.That.
tests/introspection/ApiTypoTest.cs Added an allowed typo and converted several assertions to Assert.That.
tests/introspection/ApiStructTest.cs Converted the final struct validation assertion to Assert.That.
tests/introspection/ApiSignatureTest.cs Updated a failure message to interpolated-string form.
tests/introspection/ApiSelectorTest.cs Converted selector validation assertions to Assert.That.
tests/introspection/ApiProtocolTest.cs Converted protocol validation assertions to Assert.That.
tests/introspection/ApiPInvokeTest.cs Converted P/Invoke validation assertions to Assert.That.
tests/introspection/ApiFieldTest.cs Converted field validation assertions to Assert.That.
tests/introspection/ApiCtorInitTest.cs Converted ctor/initializer validation assertions to Assert.That.
tests/introspection/ApiCoreImageFiltersTest.cs Converted filter/protocol/key validation assertions to Assert.That.
tests/introspection/ApiCMAttachmentTest.cs Converted attachment assertions to Assert.That.
tests/introspection/ApiClassPtrTest.cs Converted class pointer assertions to Assert.That.
tests/introspection/ApiBaseTest.cs Updated ReportError to use string.Format before Assert.Fail.
Comments suppressed due to low confidence (6)

tests/introspection/ApiSelectorTest.cs:1576

  • This assertion now interpolates ErrorData unconditionally, which will allocate ErrorData.ToString() on every successful run. Consider restoring the previous conditional suffix (only include ErrorData when Errors != 0) to keep the passing path allocation-free.
			Assert.That (Errors, Is.EqualTo (0), $"{Errors} errors found in {n} static selector validated:\n{ErrorData}\n");

tests/introspection/ApiCoreImageFiltersTest.cs:538

  • This assertion unconditionally interpolates ErrorData, which evaluates ErrorData.ToString() even when there are no errors. Consider conditional formatting so passing runs don't allocate large strings.
			Assert.That (Errors, Is.EqualTo (0), $"{Errors} potential errors found:\n{ErrorData}\n");

tests/introspection/ApiProtocolTest.cs:901

  • Same as above: Assert.That (0, Is.EqualTo (Errors), ...) inverts actual/expected and makes the assertion failure output harder to interpret. Prefer Assert.That (Errors, Is.EqualTo (0), ...).
			Assert.That (0, Is.EqualTo (Errors), $"{Errors} types conforms to NSSecureCoding but does not implement INSSecureCoding: {String.Join ('\n', list)}");

tests/introspection/ApiProtocolTest.cs:948

  • This assertion has actual/expected inverted (0 is the actual). Swap to assert on Errors being equal to 0 so NUnit reports the error count as the actual value when failing.
			Assert.That (0, Is.EqualTo (Errors), $"{Errors} types conforms to NSCoding but does not implement INSSecureCoding");

tests/introspection/ApiProtocolTest.cs:967

  • This Assert.That inverts actual/expected (0 is the actual), which reduces the usefulness of NUnit's failure output. Prefer Assert.That (Errors, Is.EqualTo (0), ...).
			Assert.That (0, Is.EqualTo (Errors), $"{Errors} types conforms to NSCopying but does not implement INSCopying: {String.Join ('\n', list)}");

tests/introspection/ApiProtocolTest.cs:986

  • This assertion currently uses 0 as the actual value and Errors in the constraint, which makes failures harder to read. Swap to assert Errors (actual) equals 0.
			Assert.That (0, Is.EqualTo (Errors), $"{Errors} types conforms to NSMutableCopying but does not implement INSMutableCopying: {String.Join ('\n', list)}");

}
}
Assert.AreEqual (0, Errors, "{0} errors found in {1} instance selector validated{2}", Errors, n, Errors == 0 ? string.Empty : ":\n" + ErrorData.ToString () + "\n");
Assert.That (Errors, Is.EqualTo (0), $"{Errors} errors found in {n} instance selector validated:\n{ErrorData}\n");
}
}
Assert.AreEqual (0, Errors, "{0} errors found in {1} symbol lookups{2}", Errors, n, Errors == 0 ? string.Empty : ":\n" + ErrorData.ToString () + "\n");
Assert.That (Errors, Is.EqualTo (0), $"{Errors} errors found in {n} symbol lookups:\n{ErrorData}\n");
n++;
}
Assert.AreEqual (0, Errors, "{0} potential errors found in {1} default ctor validated{2}", Errors, n, Errors == 0 ? string.Empty : ":\n" + ErrorData.ToString () + "\n");
Assert.That (Errors, Is.EqualTo (0), $"{Errors} potential errors found in {n} default ctor validated:\n{ErrorData}\n");
Console.WriteLine (to_confirm_manually);
}
Assert.AreEqual (0, Errors, "{0} potential errors found{1}", Errors, Errors == 0 ? string.Empty : ":\n" + ErrorData.ToString () + "\n");
Assert.That (Errors, Is.EqualTo (0), $"{Errors} potential errors found:\n{ErrorData}\n");
}
}
Assert.AreEqual (0, Errors, "{0} errors found in {1} fields validated: {2}", Errors, n, string.Join (", ", failed_properties));
Assert.That (Errors, Is.EqualTo (0), $"{Errors} errors found in {n} fields validated: {string.Join (", ", failed_properties)}");
{
IntPtr protocol = Runtime.GetProtocol (protocolName);
Assert.AreNotEqual (protocol, IntPtr.Zero, protocolName);
Assert.That (IntPtr.Zero, Is.Not.EqualTo (protocol), protocolName);
}
});
Assert.AreEqual (Errors, 0, "{0} types conforms to NSCoding but does not implement INSCoding: {1}", Errors, String.Join ('\n', list));
Assert.That (0, Is.EqualTo (Errors), $"{Errors} types conforms to NSCoding but does not implement INSCoding: {String.Join ('\n', list)}");
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

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

Pipeline on Agent
Hash: 697b54b8ea3060ff98ede362d4a571ca0a820104 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #697b54b] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 697b54b8ea3060ff98ede362d4a571ca0a820104 [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: 697b54b8ea3060ff98ede362d4a571ca0a820104 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #697b54b] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 697b54b8ea3060ff98ede362d4a571ca0a820104 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #697b54b] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 175 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. (⚠️ Html Report Publish failed ⚠️) 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 Publish failed ⚠️) Download
✅ fsharp: All 4 tests passed. [attempt 2] 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. [attempt 2] Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 16 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 16 tests passed. 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 Publish failed ⚠️) 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: 697b54b8ea3060ff98ede362d4a571ca0a820104 [PR build]

@rolfbjarne
rolfbjarne merged commit c91db64 into main May 18, 2026
53 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