Skip to content

[DRK-2616] Move DKNet test code from xunit 2 to xunit.v3 - #548

Merged
baoduy merged 5 commits into
devfrom
feature/drk-2622-xunit-v3
Nov 26, 2026
Merged

baoduy merged 5 commits into
devfrom
feature/drk-2622-xunit-v3

Conversation

@baoduy

@baoduy baoduy commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

This PR moves all DKNet test code from xunit 2.9.3 to xunit.v3: the 27 test projects, the snippet lab and the dknet-testing skill examples. Maintainers and plugin users then use the supported xunit line, the same one DKNet.Templates already uses. Spec: DRK-2616, revision 18.

 src/Directory.Packages.props
-  xunit                         2.9.3
+  xunit.v3.mtp-off              4.0.2
   xunit.runner.visualstudio     4.0.0   (unchanged)
 plugins/dknet-skills/tools/snippet-lab/Directory.Packages.props
-  xunit                         2.9.3
+  xunit.v3.extensibility.core   4.0.2
-  Aspire.Hosting(.SqlServer)    13.5.3
+  Aspire.Hosting(.SqlServer)    13.6.5  (matches src/, clears CS1705)
 IAsyncLifetime:  Task InitializeAsync/DisposeAsync  ->  ValueTask  (136 in src, 22 in the skill)

Evidence

  • Before: guards G1–G4 in XunitV3GuardTests failed at 81f5ac2, because xunit 2 was pinned in src/, in the lab and in the skill's install row and lifetime examples.
  • After: green at f86df94. The CI command found 3026 tests: 3026 passed, 0 failed, 0 skipped. The baseline at 0f617e6 found 3022, so the difference is the 4 new guards. The coverage threshold check passed (95% ≥ 80%). Mutation is n/a, because no production class changed.
  • After, snippet lab: all 13 skills print Build succeeded., and the 17 dknet-testing fences are all kept.
  • Not verified: none.

Merge danger

Door: two-way. Only test code, skill text and lab pins change; reverting the merge commit restores xunit 2.
Blast radius: repo. No NuGet package changes. @drunkcoding/dknet-skills gets the new dknet-testing text at the next release.

Details

  • In xunit.v3, CollectionBehavior(DisableTestParallelization = true) gives error CS0619. The 3 projects that used it now use [assembly: Xunit.v3.Parallelization(Mode = ParallelMode.None)], and the runner reports parallel mode = none.
  • In 5 WebApplicationFactory fixtures, new Task DisposeAsync became override ValueTask DisposeAsync. In v3, IAsyncLifetime extends IAsyncDisposable, so these methods now override the base method instead of hiding it.
  • 5 EfCore.Relational.Helpers tests now create their fixture database in Arrange. They had passed only because of xunit 2's test order, and each fails when run alone on 0f617e6.
  • xUnit1051 is suppressed in the 2 SlimBus generator test csproj files, each with a comment.
  • Container start and stop counts per image are the same before and after.

baoduy and others added 5 commits November 26, 2026 12:19
Pins the four automatable DRK-2622 scenarios: 27 test projects and the
src package pin on xunit.v3 only, the snippet lab on xunit.v3 only, the
dknet-testing skill install row, and its ValueTask lifetime shape with
all 17 csharp examples kept. Red on purpose until the stage 2 Builds land.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>
…RK-2626]

- Lab pins xunit.v3.extensibility.core 4.0.2 in place of xunit 2.9.3 (Library stays a Library).
- dknet-testing install row names xunit.v3.
- IAsyncLifetime examples use the v3 ValueTask InitializeAsync/DisposeAsync shape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>
The local Aspire.Hosting.ServiceBus.dll is built against Aspire.Hosting 13.6.5 since e65142c;
the lab's 13.5.3 pin made dknet-slimbus-cqrs fail with CS1705.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>
- Pin xunit.v3.mtp-off 4.0.2 in place of xunit 2.9.3; runner stays 4.0.0.
- IAsyncLifetime InitializeAsync/DisposeAsync return ValueTask; drop
  Xunit.Abstractions usings (ITestOutputHelper lives in Xunit in v3).
- WebApplicationFactory fixtures override DisposeAsync instead of hiding it.
- Assembly-level serial runs use Parallelization(Mode = ParallelMode.None):
  CollectionBehavior.DisableTestParallelization is an obsolete error in v3.
- Suppress xUnit1051 in the two SlimBus.Generators test projects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>
…s [DRK-2625]

These tests opened the per-class fixture database without creating it and
passed only because xunit 2 happened to run a creating test first. xunit.v3
orders test cases differently, and Remote Unit Tests run 45756321744 failed
GetDbConnection_WithClosedConnection_ShouldOpenConnection with 3D000
"database does not exist". Each test now calls EnsureCreatedAsync in its
Arrange, so it passes alone and in any order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednuget/​xunit.v3.extensibility.core@​4.0.210010090100100
Addednuget/​xunit.v3.mtp-off@​4.0.210010090100100

View full report

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Report

| Metric | Coverage |
|--------|----------|
| **Line Coverage** | 95.9% |
| **Branch Coverage** | 88.3% |
| **Method Coverage** | 91.2% |

**Lines:** 7101/undefined covered
**Branches:** 2979/undefined covered

📈 [View Full Coverage Report](https://github.com/baoduy/DKNet/actions/runs/45759820078)

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.32%. Comparing base (0f617e6) to head (f86df94).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #548      +/-   ##
==========================================
+ Coverage   93.25%   93.32%   +0.06%     
==========================================
  Files         219      219              
  Lines        7191     7191              
  Branches     1220     1220              
==========================================
+ Hits         6706     6711       +5     
+ Misses        259      254       -5     
  Partials      226      226              
Flag Coverage Δ
unittests 93.32% <ø> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@baoduy

baoduy commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Automated review gate — PR #548 [DRK-2616] Move DKNet test code from xunit 2 to xunit.v3

Score: 9.9 / 10 → APPROVED (bar 8.5, zero blocking)
Built right: 9.9/10 · Right thing: 10/10
Head f86df94 · base dev · 113 files, +334/−218 · cycle DRK-2622 (spec rev 18)

Summary

This PR does what spec §3 asks, and no more. All 27 src test projects move to xunit.v3.mtp-off 4.0.2 under the unchanged VSTest dotnet test command. The snippet lab moves to xunit.v3.extensibility.core 4.0.2, and the dknet-testing skill now teaches the xunit.v3 install and lifetime shape. No production DKNet.* file changed. No workflow, coverage.runsettings, Directory.Build.props or global.json changed. The only package edits are xunit → xunit.v3*, plus the lab's Aspire pins, which the leader approved (DRK-2626 row 6). I re-measured the test counts from the CI logs myself. They match the Build's report exactly.

Score breakdown

Category Weight Score Notes
Correctness & logic 25% 10 Dispose paths, serial attributes and fixture scopes all verified (below)
Security 20% 10 Test code and markdown only; no new package source
Testing & coverage 20% 9.5 1 nit; the MsSqlStore flake is declared LEFT OPEN, so it is not deducted
Architecture & design 15% 10 §3b holds: dependencies change only for the test projects and the lab
Spec conformance 10% 10 All §5 @new scenarios are green; @existing scenarios are proven by CI and the Build's evidence
Style & conventions 5% 10 Analyzers clean; the xUnit1051 NoWarn has a one-line reason (R1)
AI-slop gate 5% 10 —

Weighted average 9.9. No cap fired.

Verified evidence

  • No test lost or skipped (CI logs). Remote Unit Tests on base 0f617e6 (run 45753937283): 27 assemblies, 3022 total, 3022 passed, 0 skipped. On head f86df94 (run 45759598619): 3026 total, 3026 passed, 0 skipped. build-test-coverage on head (run 45759820078): 3026/3026, 0 skipped, coverage 95% ≥ 80%. Every per-assembly total is the same except Fw.Extensions.Tests, which goes from 165 to 169 (the 4 guards). The diff adds no Skip, and no Should*/Assert.* line changes.
  • Acceptance-test contract. git diff 81f5ac2..HEAD -- src/Core/Fw.Extensions.Tests/RepoGuards/XunitV3GuardTests.cs is empty. at_sha 81f5ac2 is the first commit after base, so it comes before every implementation commit. G1–G4 are green in CI.
  • Fixture lifetimes. The only types that implement both IAsyncLifetime and IDisposable are GadgetTestHost (TestHost.cs:42), GadgetAuthTestHost (TestHost.cs:181), GadgetExclusionTestHost.cs:28 and GroupScopeCrudTestHost (GroupScopeCrudTests.cs:49). Each Dispose() only disposes _connection, and each DisposeAsync() disposes it too (TestHost.cs:132, TestHost.cs:273, GadgetExclusionTestHost.cs:95, GroupScopeCrudTests.cs:115). So no cleanup lives only in Dispose(). The other files on the brief's list (AuditLogs, Events, Hooks, NpgsqlStore) have no type that disposes both ways. Their Dispose() methods belong to nested logger providers.
  • WAF new → override DisposeAsync. I checked this at MsSqlStore.Tests/Fixtures/ApiFixture.cs:87-95, NpgsqlStore.Tests/Fixtures/ApiFixture.cs:72-80 and AspCore.Idempotency.Tests/Fixtures/ApiFixture*.cs. Each override stops its container and then awaits base.DisposeAsync() once. xunit.v3 disposes a fixture once, through DisposeAsync alone, so the host and the container are each torn down once. Container stop counts are the same before and after (DRK-2625 evidence).
  • Serial groups. [assembly: Xunit.v3.Parallelization(Mode = Xunit.Sdk.ParallelMode.None)] replaces the 3 assembly-level CollectionBehavior(DisableTestParallelization = true) attributes (an error-level obsolete in v3). The xunit.v3 4.0.2 XML docs confirm ParallelMode.None disables all parallelism in the assembly. The 2 group-level CollectionDefinition(..., DisableParallelization = true) attributes and the 3 ICollectionFixture definitions are unchanged.
  • Relational.Helpers arrange (f86df94). The 5 added EnsureCreatedAsync calls (DbContextHelpersAdvancedTests.cs:104,131,212, DbContextHelpersEdgeCaseTests.cs:22,105) make the database state explicit. TableExistsAsync (DbContextHelpers.cs:102-122) does not create the database itself. So these tests passed on base only when an earlier test had already created it. Every assertion is unchanged, and every subject call (GetDbConnection, TableExistsAsync) still determines its test's result.
  • Skill. 17 fences are kept (6 + 11), with 0 no-compile markers. The install row is dotnet add package xunit.v3. The Build quotes the lab output: all 13 skills Build succeeded.
  • Loosened-check scan. One suppression, xUnit1051, in the 2 SlimBus generator test csproj, with a reason comment on the line above. No analyzer, coverage or CI config file is in the diff.

Findings

praise

  1. src/Core/Fw.Extensions.Tests/RepoGuards/XunitV3GuardTests.cs:80-86,108-113 — the guards parse with XDocument and match exact Include values. A missing repo root fails loudly, so the guards can never pass vacuously. The fence count of 17 stops anyone from deleting an example to turn G4 green.
  2. src/AspNet/AspCore.Idempotency.MsSqlStore.Tests/Fixtures/ApiFixture.cs:87-95 — the switch from new to override with base.DisposeAsync() is the right v3 shape: teardown runs once through one path.
  3. The Build's before/after evidence (per-project counts, container start/stop counts per image, coverage module list) made this review checkable. My independent CI-log check matched it exactly.

nit

  1. src/EfCore/EfCore.Relational.Helpers.Tests/DbContextHelpersAdvancedTests.cs:202 — the test name TableExistsAsync_WithNonExistingTable_ShouldReturnTrue now contradicts its explicit arrange (EnsureCreatedAsync at :212) and its assertion. The name is older than this PR, and the brief forbade renames, so this goes in Merged with.

  2. src/AspNet/AspCore.Idempotency.MsSqlStore.Tests/Integration/IdempotencyIntegrationTests.cs:75-78 (declared LEFT OPEN by the Build, so not deducted). This explains the intermittent successCount of 2–3:

    • The fixture uses ConflictHandling = CachedResult (Fixtures/ApiFixture.cs:78).
    • A duplicate that arrives after the winner's MarkKeyAsProcessedAsync gets the cached 201 replayed (DKNet.AspCore.Idempotency/Filtering/IdempotencyEndpointFilter.cs:212-215). The sequential test in the same file already asserts exactly that (:246, :269).
    • The concurrency test counts every 201, so successCount = 1 + the number of the 5 requests that did not overlap the winner.
    • The Npgsql sibling already fixed the same test. It documents this mechanism and asserts that every 201 carries the same Id (AspCore.Idempotency.NpgsqlStore.Tests/Integration/IdempotencyIntegrationTests.cs:72-80). The MsSql copy was never brought into line.

    The flaw is in the test assertion, and it predates this PR. It is not a store defect: the handler runs once. The runner change from v2 to v3 may change how often the 5 requests serialize, and so how often the flaw fires. The local sample (2/8 on head vs 0/4 on base) cannot separate the two trees. The test body, the fixture configuration, the filter and the store are all unchanged, and both CI runs on f86df94 pass. The comment at :60-62 ("the other four are turned away as conflicts") makes the same wrong assumption.

    Suggested fix, for whenever someone next touches this file: mirror the Npgsql assertion.

Out-of-scope observations

None clears the worth-fixing bar.

Gate notes

  • Release review: none. There is no auth or crypto code, no workflow change, no package-source or lockfile-source change, no gate-authored commit, and no owner-review request.
  • CI: green. build-test-coverage (10.x.x), test, codecov/patch, codecov/project, Socket ×2 and security/snyk all pass.
  • Vote: skipped, because the PR is self-authored (gh identity = PR author). This report comment is the record.

@baoduy
baoduy merged commit b4ce9d6 into dev Nov 26, 2026
7 checks passed
@baoduy
baoduy deleted the feature/drk-2622-xunit-v3 branch November 26, 2026 05:22
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