Skip to content

Build xUnit and NUnit test containers through ModuleTestComposition - #142

Merged
ipjohnson merged 1 commit into
mainfrom
agent/stp-vgdm-runners
Nov 27, 2026
Merged

ipjohnson merged 1 commit into
mainfrom
agent/stp-vgdm-runners

Conversation

@ipjohnson

Copy link
Copy Markdown
Owner

What changed

This is step 2 of "Changes, in the order they land" in docs/design/verificationglue.md.

ModuleTestCase (DependencyModules.xUnit, and DependencyModules.xUnit4, which compiles the same sources) now builds each container with one call to ModuleTestComposition.BuildAsync. It keeps the returned ModuleTestContainer objects and disposes them in DisposeContainers when Run returns. The following members are deleted: SetupServiceCollection, StartAsync, BuildServiceProvider, SetupServiceSetupAttributes, SeedEnvironment, SetupModules, DisposeProviders and the StartupValues record.

ModuleTestCommand (DependencyModules.NUnit) does the same with GetAwaiter().GetResult(), and disposes the container in its finally. The following members are deleted: Start, BuildServiceProvider, SetupServiceSetupAttributes, SeedEnvironment, SetupModules and DisposeProvider.

Each runner keeps three things of its own:

  • Its TestCaseInfo registration, made before the call.
  • A CollectModules method that returns the [ModuleTest] modules first and then the IDependencyModuleProvider attributes, widest scope first. This is the order the old SetupModules built before it reversed the list, so the load order does not change.
  • Argument publishing, through ModuleTestContainer.ResolveArgumentsAsync and Services.

The runners pass no overrides, currentTest: null and parent: null. So no ICurrentTestProvider is registered, and CurrentTest.Provider is installed as before.

Public API: none of the xUnit, xUnit4 or NUnit packages changes its public surface. Every removed member was private. The snapshots in tests/DependencyModules.Specs pass without changes on both majors.

Three small differences in disposal come from ModuleTestContainer.DisposeAsync. No existing test depends on any of them:

  • xUnit used to dispose the providers of a case in build order. It now disposes the containers in build order, and within each container it disposes the last provider built first. NUnit already used that order.
  • When disposing one provider throws, the container still disposes the other providers it tracks and then rethrows.
  • When a startup attribute throws, BuildAsync disposes the container before the exception reaches the runner. Before, xUnit disposed it later, at the end of Run.

No test failed, so I did not have to fix anything in the runners or in the entry point.

Why

docs/design/verificationglue.md Part 3, "What moves". Every runner, VerificationGlue included, should build a test's container through the same entry point. The xUnit and NUnit copies of the build order go away.

How it was tested

No existing test was edited.

  • scripts/coverage.sh 85, on xunit.v3 3: DependencyModules.Tests 896/896, SutProject.Tests 174/174, SutProject.NUnitTests 46/46 and WebApiApp.Tests 2/2, each on net8.0 and net10.0. DependencyModules.Specs 326/326. Line coverage is 92.9%, which meets the threshold of 85%.
  • scripts/test-xunit.sh 4: DependencyModules.Tests 897/897, SutProject.Tests 174/174 and WebApiApp.Tests 2/2, each on net8.0 and net10.0. DependencyModules.Specs with XunitMajor=4 326/326.
  • dotnet csharpier check . passes.
  • The xUnit, xUnit4 and NUnit projects build in Release with only the existing NU1902 warnings.

I did not run scripts/verify-packages.sh.

🤖 Generated with Claude Code


Opened by Agent Driver for step stp-vgdm-runners of Task tsk-verificationglue.

ModuleTestCase and ModuleTestCommand now call ModuleTestComposition.BuildAsync
and dispose the returned ModuleTestContainer. Their copies of the build steps
are removed. Each runner keeps its TestCaseInfo registration and the list of
modules from [ModuleTest] and the module attributes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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