Skip to content

Migrate test projects to xUnit v3 - #101

Merged
christopherread merged 4 commits into
masterfrom
test/xunit-v3-linear
Oct 25, 2026
Merged

christopherread merged 4 commits into
masterfrom
test/xunit-v3-linear

Conversation

@christopherread

Copy link
Copy Markdown
Owner

Fixes #75. Merge after #80 and #81: this branch includes their commits (cherry-picked, so history stays linear), because the xUnit v3 fixes touch the same test lines. The diff includes their changes until they merge.

Replaces #100. That branch merged #80 and #81 in, and GitVersion 6's Mainline strategy crashes on those merge commits (InvalidOperationException in MainlineVersionStrategy). The files here are identical.

Changes

  • Packages: xunit 2.9.3 (deprecated) → xunit.v3 4.0.2 in Directory.Packages.props and all 9 test projects. xunit.runner.visualstudio 4.0.1 and Microsoft.NET.Test.Sdk stay, so IDE test explorers keep working.
  • Projects: test projects are now <OutputType>Exe</OutputType>, as xUnit v3 requires.
  • Code: using Xunit.Abstractions; is removed; ITestOutputHelper is now in the Xunit namespace.
  • xUnit1051: v3's analyzer flagged 11 Task.Delay and CloseAsync calls in the broker tests that should pass TestContext.Current.CancellationToken. Fixed.
  • Test runner mode: xunit.v3 runs on Microsoft.Testing.Platform (MTP), and the .NET 10 SDK refuses to run MTP projects through the old VSTest-mode dotnet test. Microsoft documents the old route as legacy. So a new global.json opts into MTP mode with "test": { "runner": "Microsoft.Testing.Platform" }. It has no sdk section, so it doesn't pin an SDK version.
  • CI unit-test step:
    • The filter becomes dotnet test --solution Obvs.sln … -- --filter-not-trait "Category=Explicit" --ignore-exit-code 8.
    • MTP reports exit code 8 when a project runs zero tests, which is the case for the transport test projects that contain only Explicit tests.

For developers

dotnet test syntax changes in MTP mode:

  • --filter Category=Explicit → -- --filter-trait "Category=Explicit"
  • dotnet test X.csproj → dotnet test --project X.csproj
  • dotnet test X.sln → dotnet test --solution X.sln

⚠️ Interaction with #82

#82 adds a CI step that runs the broker tests with the old syntax (dotnet test Obvs.RabbitMQ.Tests --filter Category=Explicit). Whichever of #82 and this PR merges second needs that step converted to:
dotnet test --project Obvs.RabbitMQ.Tests --no-build --configuration Release -- --filter-trait "Category=Explicit" (and the same for NATS and Kafka). I'll update whichever branch is left.

Testing

  • Build: a full rebuild gives 0 warnings, 0 errors.
  • Unit tests: all 124 pass in MTP mode with the CI command. That's the same count as before, so the trait filter excludes exactly the Explicit tests.
  • NetMQ socket tests (--filter-trait "Category=Explicit"): passed in 10 of 11 runs. One run had a single failure that didn't recur in the next 8 runs. These tests rely on fixed Task.Delay timings.

🤖 Generated with Claude Code

christopherread and others added 4 commits October 25, 2026 00:01
The pub/sub tests shared port 5556 between themselves and overlapped the
5555-5558 range TestServiceBusWithNetMq binds, which xUnit runs in
parallel, and no test disposed its publishers, sources or buses. Give
each pub/sub test its own port and dispose everything before asserting.

Fixes #72

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests that waited on publish/send tasks now await them. The "returns
with no observers" tests checked .Wait(1); they now assert the returned
task is already completed, which is what the buses guarantee.

Fixes #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xunit.v3 runs on Microsoft.Testing.Platform, which the .NET 10 SDK only
supports through the new dotnet test mode, so opt in via global.json.
CI filters with xUnit's --filter-not-trait and ignores exit code 8 (no
tests ran) for the projects that only have Explicit tests. Pass
TestContext.Current.CancellationToken to delays, per xUnit1051.

Fixes #75

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@christopherread
christopherread merged commit 4997988 into master Oct 25, 2026
1 check passed
@christopherread
christopherread deleted the test/xunit-v3-linear branch October 25, 2026 07:04
christopherread added a commit that referenced this pull request Oct 25, 2026
Master now runs tests on Microsoft.Testing.Platform (#101), so use
--project and --filter-trait. The NetMQ tests no longer clash over ports
(#80), so run them too. The broker steps now come before the unit test
step, so this branch no longer edits the lines master changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
christopherread added a commit that referenced this pull request Oct 25, 2026
Master now runs tests on Microsoft.Testing.Platform (#101), so use
--project and --filter-trait. The NetMQ tests no longer clash over ports
(#80), so run them too. The broker steps now come before the unit test
step, so this branch no longer edits the lines master changed.

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.

Migrate test projects to xUnit v3

1 participant