Skip to content

Make the test suite pass in every environment and run fully in CI - #7129

Merged
thomhurst merged 53 commits into
thomhurst:mainfrom
Quattordici:fix/httpstatuscode-snapshot-test-host
Oct 19, 2026
Merged

thomhurst merged 53 commits into
thomhurst:mainfrom
Quattordici:fix/httpstatuscode-snapshot-test-host

Conversation

@Quattordici

@Quattordici Quattordici commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Scope: this PR changes only tests, CI and solution files. The production fixes it originally carried (TUnit0014 on interface implementations, Aspire exit-code culture, [AssertionFrom] expectation messages) moved to #7135, which is stacked on this one.

Description

Running all tests from an IDE (Rider on macOS, sv-SE locale) failed 26 tests that pass in CI. Investigating
them turned up several environment dependencies in the tests, two product bugs, and gaps in what CI runs.

Tests that depended on how or where they were launched

  • Generator tests built their compilation references from AppDomain.CurrentDomain.GetAssemblies(), i.e.
    whatever the process had loaded so far. IDE / dotnet test server-mode hosts load more than a plain run, so
    HttpStatusCode resolved in one mode and not the other, and the committed .NET snapshots captured the
    unresolved output. A shared TestHostReferences helper now uses TRUSTED_PLATFORM_ASSEMBLIES on .NET
    (unchanged on .NET Framework), and the snapshots are corrected. The paths are sorted, since the TPA order differs
    between Linux and macOS and generators emit referenced assemblies in reference order (this reordered
    DuplicateTypeNameAcrossAssembliesTests' snapshot on macOS).
  • The PublicAPI path scrubber only handled CI's deterministic /_/ source paths. A local checkout path longer than
    80 characters is wrapped by the API generator into "..." + continuation lines, leaving a fragment behind
    (OpenTelemetry_Library_Has_No_API_Changes failed on macOS). Whole path literals, including continuations,
    are now scrubbed.
  • TUnit.Engine.Tests launched TUnit.TestProject, its F#/VB siblings and HtmlReportDefaults from hard-coded
    bin/Release folders, so a Debug run from an IDE failed or ran stale binaries. They are now build-only project
    references located by the test assembly's own configuration (CI unchanged).
  • Tests starting dotnet build/dotnet run used whatever dotnet is first on PATH (exit 155,
    SdkResolveFailure, when that installation lacks the global.json SDK). A shared DotNetCli helper prefers
    DOTNET_HOST_PATH, then the running installation; RpcTests now report the build output on failure.
  • Culture-sensitive tests are culture-independent instead of assuming en-US (verified under en-US, sv-SE,
    de-DE, tr-TR, ar-SA).

Product bugs found along the way

  • [AssertionFrom] assertions with a custom message reported Expected be null or empty (double space, no
    "to"); the generator now emits to {not }.... Snapshots updated, regression test added.
  • TUnit0014 flagged public methods implementing an interface (e.g. ITestStartEventReceiver.OnTestStart),
    which cannot be made private; such methods are now skipped.
  • TUnit.Aspire printed exit codes such as -532462766 with U+2212 under some cultures; exit codes are now
    formatted invariantly.

Test project and CI consistency

  • TUnit.SourceGenerator.IncrementalTests was an xUnit v2/VSTest project that dotnet test refused under the
    MTP-only global.json (aborting solution-wide runs) and that CI never ran; it is migrated to TUnit and gets a
    pipeline module.
  • TUnit.Assertions.SourceGenerator.Tests had no pipeline module; added. Test modules now run every framework
    a project targets (most ran net10.0 only; analyzer modules a single fixed TFM).
  • ArgumentFormatter's only tests lived in a directory without a project file and never compiled; ported to
    TUnit.UnitTests. Dead/stray test files removed; tests disabled for APIs that now exist are revived.
  • TUnit.OpenTelemetry.Tests and TUnit.Aspire.Tests now use the shared eng/TestProject.props/.targets
    (they lacked the assertion analyzers). Unused xUnit references removed. The fast test projects are added to
    TUnit.Dev.slnx.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

Required

  • I have read the Contributing Guidelines
  • If this is a new feature, I started a discussion first and received agreement
  • My code follows the project's code style (modern C# syntax, proper naming conventions)
  • I have written tests that prove my fix is effective or my feature works

TUnit-Specific Requirements

  • Dual-Mode Implementation: not applicable (no discovery/execution changes)
  • Snapshot Tests: If I changed source generator output or public APIs:
    • I ran TUnit.Core.SourceGenerator.Tests and/or TUnit.PublicAPI tests
    • I reviewed the .received.txt files and accepted them as .verified.txt
    • I committed the updated .verified.txt files
  • Performance: not applicable
  • AOT Compatibility: not applicable

Testing

  • All existing tests pass (dotnet test)
  • I have added tests that cover my changes
  • I have tested both source-generated and reflection modes (if applicable)

Additional Notes

  • Verified on Linux: every test project on net8.0/net9.0/net10.0 in Debug and Release, both via dotnet test
    (server mode) and as plain executables, plus the changed pipeline modules' exact Release commands.
  • The two macOS-only snapshot failures were reproduced on Linux (reversed reference order; source paths mapped
    with -p:PathMap to the macOS checkout path) before fixing. The PublicAPI tests pass with local, CI
    (/_/), long macOS and long Windows-style source paths.
  • Verified on macOS (sv-SE locale) by running the whole TUnit.Dev.slnx in Rider (Debug): 6004 tests with no
    failures except the 7 TUnit.RpcTests net8.0 variants, which exit with 150 (FrameworkMissingFailure)
    because that machine's dotnet has no .NET 8 runtime; their net10.0 variants pass.
  • Not verifiable off Windows: the net472 legs. The Net4_7 snapshots received the same mechanical one-line
    substitution as the regenerated .NET ones, and the new assertions-generator module includes net472 on
    Windows, so Windows CI is their first real check.
  • CI runs more framework legs than before, so it will take somewhat longer.
  • Related follow-up, not fixed here: [Bug]: Test display names format numeric arguments with the current culture #7126 (test display names format numeric arguments with the current
    culture). Found while making the culture-sensitive tests above culture-independent.

Summary by CodeRabbit

  • Bug Fixes

    • Public interface implementations no longer trigger missing-test-attribute warnings.
    • Assertion failure messages use consistent phrasing and handle custom text and parameter placeholders more reliably.
    • Aspire diagnostic exit codes display consistently across locales.
    • Test runs use the configured build output and locate the appropriate .NET executable.
    • Memory assertion guidance now points to the supported assertion location; span assertion extensions are obsolete.
  • Documentation

    • Updated assertion extensibility guidance with examples of quoted parameter values and expectation-message formatting.
  • Tests

    • Expanded assertion and incremental source-generator coverage.
    • Added test pipeline coverage across additional .NET versions.
    • Added coverage for assertion message formatting and source-path scrubbing.

Loading
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.

2 participants