Repository navigation
[tests] Upgrade tests/introspection to NUnit v4 Assert.That syntax - #25442
Conversation
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>
There was a problem hiding this comment.
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/...) toAssert.Thatconstraints 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
ErrorDataunconditionally, which will allocateErrorData.ToString()on every successful run. Consider restoring the previous conditional suffix (only includeErrorDatawhenErrors != 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 evaluatesErrorData.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. PreferAssert.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 (
0is the actual). Swap to assert onErrorsbeing 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.Thatinverts actual/expected (0is the actual), which reduces the usefulness of NUnit's failure output. PreferAssert.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
0as the actual value andErrorsin the constraint, which makes failures harder to read. Swap to assertErrors(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)}"); |
✅ [PR Build #697b54b] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #697b54b] 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 #697b54b] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [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. ( macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Convert classic NUnit assertions to NUnit v4's constraint-based
Assert.That syntax in the introspection test project.