Skip to content

Migrate unit tests from xunit v2 to xunit.v3 - #8

Merged
ardalis merged 1 commit into
net11-upgradefrom
xunit-v3
Nov 25, 2026
Merged

ardalis merged 1 commit into
net11-upgradefrom
xunit-v3

Conversation

@ardalis

@ardalis ardalis commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Closes #5. Stacked on #4. The base is net11-upgrade; retarget to main once #4 merges.

Summary

  • xunit 2.9.3 → xunit.v3 4.0.3. The test project is now <OutputType>Exe</OutputType>.
  • xunit.v3 4.x runs on Microsoft.Testing.Platform (MTP) v2. On the .NET 10+ SDK, MTP no longer runs through VSTest's dotnet test. The new global.json therefore opts into the MTP dotnet test experience ("test": { "runner": "Microsoft.Testing.Platform" }). It also pins the SDK to 11.0.100 with rollForward: latestFeature.
  • Removed packages that only work with VSTest:
    • Microsoft.NET.Test.Sdk: not needed with MTP
    • xunit.runner.visualstudio: VS and VS Code Test Explorer run MTP projects directly
    • coverlet.collector → coverlet.MTP 10.1.1
  • No test code changes were needed: the tests don't use IAsyncLifetime, ITestOutputHelper or Xunit.Abstractions.

Command-line changes

dotnet test NimblePros.SharedKernel.slnx still works, but VSTest-style switches don't. The MTP equivalents are:

VSTest MTP
--logger trx --report-xunit-trx
--collect "XPlat Code Coverage" --coverlet --coverlet-output-format cobertura
--results-directory <dir> unchanged

⚠️ Interaction with #7: #7 adds --logger trx --collect "XPlat Code Coverage" to ci.yml and turns on NuGet lock files. Whichever of #7 and this PR merges second needs the test step changed to the MTP flags above, and the lock files regenerated (dotnet restore). I'll handle that once the merge order is decided.

Test plan

  • dotnet build -c Release succeeds with no warnings
  • dotnet test: 10/10 tests pass on net11.0 through MTP
  • dotnet test --report-xunit-trx --coverlet --coverlet-output-format cobertura --results-directory artifacts/test-results produces a .trx file and coverage.cobertura.*.xml
  • CI green

🤖 Generated with Claude Code

- xunit 2.9.3 -> xunit.v3 4.0.3 (test project is now an Exe)
- Opt into the MTP dotnet test experience via global.json (required by
  xunit.v3 4.x on the .NET 10+ SDK); pin SDK 11.0.100 with latestFeature
- Replace VSTest-only packages: drop Microsoft.NET.Test.Sdk and
  xunit.runner.visualstudio; coverlet.collector -> coverlet.MTP 10.1.1

Closes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ardalis
ardalis merged commit 2caa688 into net11-upgrade Nov 25, 2026
@ardalis ardalis mentioned this pull request Nov 25, 2026
2 of 3 tasks
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