Repository navigation
Add DependencyModules.xUnit4 for xunit.v3 4.x - #118
Merged
Merged
Conversation
xunit.v3 4.0 changed ISelfExecutingXunitTestCase.Run and made the old RunXunitTestCase throw. A ModuleTestCase built against 3.x therefore does not load on 4.x, and a run-time lookup cannot supply a missing interface method. DependencyModules.xUnit stays on [3.2.2,4.0.0). DependencyModules.xUnit4 compiles the same sources against [4.0.0,5.0.0), and Impl/ModuleTestCase.XunitMajor.cs holds the code that differs. The xUnit test projects run on both majors through XunitMajor. The 4.x leg uses xunit.v3.mtp-off, because Microsoft.Testing.Platform v2 refuses VSTest dotnet test on the .NET 10 SDK. A weekly workflow runs the tests on the newest xunit.v3, prereleases included. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ting (#119) Each runner package installs an ICurrentTestProvider over its test framework's own context: TestContext.Current for xUnit, and TestExecutionContext.CurrentContext for NUnit. A library can then read the test that runs, and write to its output, with no reference to a test framework. Hardened can drop [HardenedTest] and its two runner packages for [ModuleTest]. xUnit's output helper throws when a background task writes after its test has finished. The xUnit provider drops that line, so a logger does not throw into the application under test. Co-authored-by: Ian Johnson <ianjohnson@mac.mynetworksettings.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch also carries #119, which was merged into it:
ICurrentTestProvider,CurrentTest, andTestOutputLoggerProviderin DependencyModules.Testing. #119 describes that part.What
DependencyModules.xUnit4, a new package that compiles the DependencyModules.xUnit sources against xunit.v3[4.0.0,5.0.0), with its own assembly name.DependencyModules.xUnitstays on[3.2.2,4.0.0).Impl/ModuleTestCase.XunitMajor.cs:Runfor each major, andCreateTest. On 4.x,CreateTestgives a row'sLabelandDisableParallelizationtoXunitTest, as[Theory]does. The discoverer needs no#if, because the samelabel: nullcall binds to the overload of each major.XunitMajorinDirectory.Build.propsselects the xunit package, the runner, and the DependencyModules project for the three xUnit test projects.scripts/test-xunit.sh 4runs them on 4.x, in build-package and in release.xunit-prerelease.yamlruns them each week on the newest xunit.v3 on nuget.org, prereleases included.verify-packages.shpacks the new package. It now fails if a test package's framework range does not stop below the next major.dotnet teston 4.x. The README, the testing overview, and CONTRIBUTING are updated.Why
The plan in #117 was a run-time lookup for
GetTestCaseDetailsand a wider range. Built against 3.2.2 with that lookup, every[ModuleTest]on 4.0.1 then failed at discovery:4.0 added
ParallelMode,ExecutionScheduler, andFixtureMappingManagerparameters toISelfExecutingXunitTestCase.Run. The six-parameterXunitRunnerHelper.RunXunitTestCasethatRuncalls is[Obsolete(error: true)]in 4.x and throwsNotSupportedException. A 3.2.2 build cannot declare the newRun, and a run-time lookup cannot supply an interface method. A Mono.Cecil pass over every xUnit reference in the 3.2.2 build found these two, the knownGetTestCaseDetailsoverload, and one constructor that 4.x only marks obsolete.One design keeps a single package: stop being self-executing and dispose in
PostInvoke. All suites passed on both majors that way. ButPostInvokeis synchronous, so it has to block onDisposeAsync. A probe service that disposes through the context it was created on hung under the Aggressive algorithm, on both majors. The awaitedRundisposes the same service in 5 ms. So, as #117 says for this case, 4.x gets its own line.Notes
xunit.v3.mtp-off. The Microsoft.Testing.Platform v2 thatxunit.v34.x brings refuses the VSTestdotnet teston the .NET 10 SDK, and xUnit ships mtp-off for that case.GetTestCaseDetailsoverload went in 4.0.0-pre.81 (2026-04-12), the oldRunXunitTestCasestarted to throw in pre.108 (2026-05-02), andRunchanged in pre.154 (2026-07-17). The weekly workflow would have failed on each.XunitCurrentTestProviderreadsIXunitTestClass.Class, which 4.0 moved toICoreTestClass. Add CurrentTest and TestOutputLoggerProvider to DependencyModules.Testing #119, now merged into this branch, gives Hardened a framework-neutral seam, so it can drop[HardenedTest].Verified
scripts/coverage.sh 85: 1069, 161, 39, and 2 tests pass on net8.0 and net10.0, at 92.3% line coverage.scripts/test-xunit.sh 4: 1070, 161, and 2 tests pass on both TFMs, on xunit.v3.mtp-off 4.0.1 with runner 4.0.0.scripts/verify-packages.sh,dotnet csharpier check ., andnpm run buildpass.ICoreTestCasein the interfaces ofModuleTestCase, and the three newRunparameters.scripts/coverage.sh 85passes 1081, 171, 46, and 2 tests at 92.3% line coverage, andscripts/test-xunit.sh 4passes 1082, 171, and 2.Closes #117.
🤖 Generated with Claude Code