Skip to content

Test hygiene: enforce NUnit1032, ban the classic assert model, fix SchedulerFactoryObject.Dispose - #386

Merged
lahma merged 5 commits into
mainfrom
4x/test-hygiene
Nov 3, 2026
Merged

lahma merged 5 commits into
mainfrom
4x/test-hygiene

Conversation

@lahma

@lahma lahma commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Follow-ups to the NUnit 5 / Microsoft.Testing.Platform migration (#383).

  • SchedulerFactoryObject.Dispose no longer throws a NullReferenceException on a factory that was never initialized; it returns early when there is no scheduler. A factory that is only half initialized still gets its scheduler shut down. New tests: TestDispose_NotInitialized, which failed before the fix, and TestDispose_Initialized_ShutsDownScheduler. This is the only src/ change.
  • NUnit1032 is enforced at its default severity, so a violation fails the build.
    • 71 fixture members across 64 files are now disposed in [TearDown].
    • Two justified #pragmas remain: WebApplicationTests.host, a shared AspFixtureHost released through ReleaseInstance, and the static queue shared by SimpleMessageListenerContainerTests.
    • test/.editorconfig held only the suggestion override, so it is deleted.
    • Teardown order follows container convention, with child factories disposed before their parents.
  • The classic assert model is a build error in test/. test/Directory.Build.targets removes nunit.framework.legacy.dll from the compile references. The assembly still goes to the output, because NUnit's runtime needs it. ClassicAssert, StringAssert, CollectionAssert, FileAssert, DirectoryAssert, the Assert.AreEqual-style extension members and the NUnit.Framework.Legacy namespace all fail to compile, on both TFMs.
    • Raising the NUnit.Analyzers classic-model rules to error was rejected. They miss FileAssert, DirectoryAssert, the extension members and six ClassicAssert members, and raising them all to error brings in about 1,700 unrelated errors.
    • BannedApiAnalyzers was rejected. It misses the members ClassicAssert inherits from the base class it shares with Assert.
  • Asserts that compared a value with itself were rewritten to test something real:
    • AbstractAopProxyTests.Equality now compares two distinct proxies, both ways.
    • PropertyValueTests.TestEquals adds the cases that must not be equal.
    • XmlObjectFactoryTests now asserts that factory-method arguments are passed through as the same objects.
    • The tautological SimpleTest.cs (Assert.AreEqual(2, 1 + 1)) is deleted.
  • EnableNUnitRunner is turned off for projects that set UseNUnit=false.
  • AGENTS.md: the test bullet now mentions the assert-model ban and NUnit1032.

Verification

  • ./build.cmd Test --skip CompileExamples, net10.0 and net472. The only failure is FormatUsingDefaults on both TFMs, which depends on this machine's regional settings.

    Tests Run
    Spring.Core.Tests 5334
    Spring.Aop.Tests 1006
    Spring.Data.Tests 372
    Spring.Scheduling.Quartz3.Tests 150
    Spring.Messaging.Nms.Tests 127
    Spring.Data.NHibernate5.Tests 80
    Spring.Testing.NUnit.Tests 28
    Spring.Testing.Microsoft.Tests 8
    Spring.Web.Mvc5.Tests 7
  • Spring.Web.Tests was run again after rebasing onto Remove the ASMX web service exporter from Spring.Web #384: 192 passed, 8 skipped. The affected Core fixtures were also run again after the review fixes.

  • The integration projects (Data, NHibernate5, Quartz3, Web.Conversation) were compiled but not run. Their teardown changes are scoped to SetUp, and their existing DB cleanup still runs before the context is disposed. They should get a --test-integration-data run before release.

  • spring-reviewer accepted it, with three small follow-ups that are now in the last commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LGkLQuAuUjvRjrU1AcTsmk

lahma and others added 5 commits November 3, 2026 22:39
…initialized

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGkLQuAuUjvRjrU1AcTsmk
Signed-off-by: Marko Lahma <marko.lahma@gmail.com>
…nitRunner to NUnit projects

test/Directory.Build.targets drops nunit.framework.legacy.dll from the compiler's
references, which covers ClassicAssert, StringAssert, CollectionAssert, FileAssert,
DirectoryAssert and the Assert.AreEqual extension members. EnableNUnitRunner is
switched off for projects that set UseNUnit to false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGkLQuAuUjvRjrU1AcTsmk
Signed-off-by: Marko Lahma <marko.lahma@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGkLQuAuUjvRjrU1AcTsmk
Signed-off-by: Marko Lahma <marko.lahma@gmail.com>
Removes the test/.editorconfig override that held NUnit1032 at suggestion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGkLQuAuUjvRjrU1AcTsmk
Signed-off-by: Marko Lahma <marko.lahma@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGkLQuAuUjvRjrU1AcTsmk
Signed-off-by: Marko Lahma <marko.lahma@gmail.com>
@lahma
lahma merged commit ed5e265 into main Nov 3, 2026
3 checks passed
@lahma
lahma deleted the 4x/test-hygiene branch November 3, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant