Skip to content

Migrate VMR test projects to xunit.v3 and Microsoft.Testing.Platform - #8060

Merged
ViktorHofer merged 10 commits into
mainfrom
ViktorHofer/test-xunit-v3-mtp
Aug 10, 2026
Merged

ViktorHofer merged 10 commits into
mainfrom
ViktorHofer/test-xunit-v3-mtp

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Migrates the test projects under test/ from xUnit.net v2 on VSTest to xUnit.net v3 on Microsoft.Testing.Platform (MTP).

Build configuration

Arcade's test infrastructure is disabled (DisableArcadeTestFramework). MTP contributes its own Test → InvokeTestingPlatform target that builds the project and executes the test application, so Arcade's parallel Test/RunTests targets and the xunit package references it injects aren't needed. eng/Tests.targets is deleted; it overrode the Test target to depend on VSTest, which would otherwise shadow MTP's.

That leaves one execution path shared by build.cmd -test, dotnet test and dotnet msbuild -t:Test. global.json declares the MTP runner so dotnet test uses it too.

The per-project VSTest properties (VSTestLogger, VSTestCLIRunSettings, VSTestResultsDirectory, VSTestUseMSBuildOutput) collapse into a single TestingPlatformCommandLineArguments property in test/Directory.Build.props.

Packages reduce to a single xunit.v3 reference: it pulls in xunit.v3.mtp-v2 (core, assert, analyzers), which brings MTP and its MSBuild integration transitively. Microsoft.Testing.Platform.MSBuild is pinned forward because xunit.v3 asks for an older version that predates --ignore-exit-code.

Two behaviours are worth calling out:

  • Reports are now requested explicitly. MTP emits none by default, and every pipeline that publishes results from this repo globs for trx. They go to artifacts/TestResults as <Project>.trx / .xml / .html (the xunit writers, so no extra Microsoft.Testing.Extensions.* package).
  • All-skipped runs no longer fail. Many of these tests are conditional on the build configuration (source-only, official build, availability of an SDK archive), and MTP reports "zero tests ran" as exit code 8. Real test failures still fail the build — verified.

Code changes

The custom [ConditionalFact] / [ConditionalTheory] attributes are replaced by xunit v3's built-in support:

[ConditionalFact(typeof(SdkContentTests), nameof(IncludeSdkContentTests))]
// becomes
[Fact(Skip = "Condition not met: IncludeSdkContentTests", SkipUnless = nameof(IncludeSdkContentTests))]

The v2-only discoverer infrastructure they relied on (ConditionalFactDiscoverer, ConditionalTheoryDiscoverer, ConditionalTestDiscoverer, SkippedTestCase, …) is deleted — 7 files, ~370 lines.

using Xunit.Abstractions; is gone throughout; ITestOutputHelper moved into the Xunit namespace and gained Write/Output members, which DebugTestOutputHelper now implements.

Runtime selection

xunit.v3 requires an app host, and MTP launches that executable directly rather than through the dotnet muxer. An app host ignores PATH — it resolves a runtime through DOTNET_ROOT and otherwise falls back to the machine-wide install. Arcade's runner target used to set this; with Arcade's test infrastructure disabled, nothing did, so tests silently ran on the machine-wide runtime instead of the repo-local SDK, and would fail outright on a machine with no .NET installed:

no DOTNET_ROOT   -> .NET 11.0.0-preview.7.26377.110   # machine-wide
with DOTNET_ROOT -> .NET 11.0.0-preview.6.26359.118   # repo-local .dotnet/

microsoft/testfx#10413 fixes this upstream: InvokeTestingPlatformTask now configures DOTNET_ROOT for app host launches itself, and the InvokeTestingPlatform target gained a TestingPlatformEnvironmentVariable item for passing additional variables through. No workaround is needed in this repo.

That fix isn't on the regular feeds yet, so MicrosoftTestingPlatformVersion is overridden to a build from the testfx test-tools preview channel, which the root NuGet.config now references. Both should be reverted once a release containing the fix flows to the regular feeds.

Pipelines

sdk-diff-tests.yml and vmr-license-scan.yml invoke dotnet test directly rather than going through Arcade, so their VSTest arguments are translated:

before after
--filter "Category=SdkContent" --filter-trait "Category=SdkContent"
--filter "FullyQualifiedName=..." --filter-method "..."
--logger:'console;verbosity=detailed' --output Detailed
--logger:'trx;LogFileName=...' (now a default in test/Directory.Build.props)

MTP has no unified --filter; the platform itself only provides --filter-uid, and the --filter-class/method/namespace/trait options come from xunit.

Validation

All five projects build with zero warnings. -t:Test and dotnet test both pass, emit trx/xml/html into artifacts/TestResults, and leave nothing behind next to the test binaries. Verified that an all-skipped project exits 0 while a genuine failure still exits non-zero, and that tests are hosted on the repo-local SDK with no DOTNET_ROOT set in the environment.

The test projects under test/ were xunit v2 running on VSTest. Move them to
xunit.v3 on Microsoft.Testing.Platform (MTP).

Build configuration:
- Disable Arcade's test infrastructure (DisableArcadeTestFramework). MTP brings
  its own Test/InvokeTestingPlatform target, so Arcade's parallel Test/RunTests
  targets and the xunit package references it injects are no longer needed.
- Replace the VSTest properties (VSTestLogger, VSTestCLIRunSettings,
  VSTestResultsDirectory, VSTestUseMSBuildOutput) with a single
  TestingPlatformCommandLineArguments property, and delete eng/Tests.targets,
  which forced the Test target to depend on VSTest.
- Reference the xunit.v3 meta package; it pulls in xunit.v3.mtp-v2 (core, assert
  and analyzers) which in turn brings MTP and its MSBuild integration.
  Microsoft.Testing.Platform.MSBuild is pinned forward because xunit.v3 asks for
  an older version that doesn't support --ignore-exit-code.
- Declare the MTP runner in global.json so dotnet test uses the same path.

Test reports are emitted explicitly (MTP produces none by default) into
artifacts/TestResults, matching what the pipelines publish. Runs where every
test is skipped no longer fail: many of these tests are conditional on the build
configuration, and MTP reports "zero tests ran" as exit code 8.

Code changes:
- Convert the custom [ConditionalFact]/[ConditionalTheory] attributes to xunit
  v3's built-in [Fact(SkipUnless=...)]/[Theory(SkipUnless=...)] and delete the
  v2-only discoverer infrastructure they depended on.
- Drop the Xunit.Abstractions using directives; ITestOutputHelper moved into the
  Xunit namespace and gained Write/Output members.

Test applications are launched directly as app hosts rather than through the
dotnet muxer, and an app host resolves its runtime via DOTNET_ROOT rather than
PATH. Set it to the repo-local SDK so tests don't silently run against whatever
.NET happens to be installed on the machine. See microsoft/testfx#10342.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

ViktorHofer and others added 2 commits July 30, 2026 18:10
…OOT workaround

microsoft/testfx#10413 makes InvokeTestingPlatformTask configure DOTNET_ROOT
for app host launches automatically, so the inline task that set the variable
on the MSBuild process is no longer needed.

That fix isn't on the regular feeds yet, so pick it up from the testfx
test-tools preview channel (https://aka.ms/mstest/preview) by overriding the
Arcade default for MicrosoftTestingPlatformVersion. Both can be reverted once
a release containing the fix flows to the regular feeds.

Verified that the test applications still run against the repo-local .NET
installation with no DOTNET_ROOT set in the environment.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
@ViktorHofer
ViktorHofer force-pushed the ViktorHofer/test-xunit-v3-mtp branch from e8a3ded to 261c93a Compare August 4, 2026 08:29
@ViktorHofer
ViktorHofer marked this pull request as ready for review August 4, 2026 08:30
Copilot AI review requested due to automatic review settings August 4, 2026 08:30
@ViktorHofer
ViktorHofer requested review from a team as code owners August 4, 2026 08:30
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the VMR-level test projects under test/ from xUnit.net v2 + VSTest to xUnit.net v3 running on Microsoft.Testing.Platform (MTP), simplifying test execution to a single MTP-based path and updating pipeline invocations accordingly.

Changes:

  • Replaces custom conditional test discovery (ConditionalFact/ConditionalTheory discoverers + skipped test case plumbing) with xUnit v3’s built-in SkipUnless support and removes the v2-only infrastructure.
  • Switches test execution configuration to MTP via TestingPlatformCommandLineArguments, including explicit TRX/XML/HTML report emission into artifacts/TestResults.
  • Updates repo configuration and pipelines for the MTP runner and pins a preview Microsoft.Testing.Platform build via a new feed entry.
Show a summary per file
File Description
test/TestUtilities/TestUtilities.csproj Updates xUnit dependencies for v3 extensibility usage in test utilities.
test/TestUtilities/SkippedTestCase.cs Removes xUnit v2-specific skipped test case implementation.
test/TestUtilities/ExecuteHelper.cs Updates ITestOutputHelper namespace usage for xUnit v3.
test/TestUtilities/ConditionalTheoryDiscoverer.cs Removes xUnit v2 conditional theory discoverer implementation.
test/TestUtilities/ConditionalTheoryAttribute.cs Removes xUnit v2 conditional theory attribute.
test/TestUtilities/ConditionalTestDiscoverer.cs Removes shared xUnit v2 conditional discovery logic.
test/TestUtilities/ConditionalFactDiscoverer.cs Removes xUnit v2 conditional fact discoverer implementation.
test/TestUtilities/ConditionalFactAttribute.cs Removes xUnit v2 conditional fact attribute.
test/TestUtilities/ConditionalDiscovererException.cs Removes exception type used by the removed v2 discoverers.
test/TestUtilities/BaselineHelper.cs Updates ITestOutputHelper namespace usage for xUnit v3.
test/Microsoft.DotNet.Tests/SourceTarballContentTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.Tests/PackageSourceMappingsTests.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.Tests/Microsoft.DotNet.Tests.csproj Removes VSTest-specific project properties.
test/Microsoft.DotNet.Tests/CentralPackageManagementTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.Tests/BinaryScanTest.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/WebScenarioTests.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/Utilities.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/TestBase.cs Updates ITestOutputHelper namespace usage for xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/SymbolsTests.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/SourcelinkTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/SourceBuiltArtifactsTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/SdkTests.cs Updates ITestOutputHelper namespace usage for xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/SdkContentTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/PoisonTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/OmniSharpTests.cs Converts conditional theories to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/Microsoft.DotNet.SourceBuild.Tests.csproj Removes VSTest-specific project properties.
test/Microsoft.DotNet.SourceBuild.Tests/LicenseScanTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.SourceBuild.Tests/HttpClientExtensions.cs Updates ITestOutputHelper namespace usage for xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/DotNetWatchTests.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/DotNetHelper.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/DotNetFormatTests.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/DebugTests.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/DebugTestOutputHelper.cs Updates to xUnit v3 ITestOutputHelper shape (adds Output/Write).
test/Microsoft.DotNet.SourceBuild.Tests/BaselineHelper.cs Removes xUnit v2 abstractions usage in favor of xUnit v3.
test/Microsoft.DotNet.SourceBuild.Tests/ArtifactsSizeTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.Reproducibility.Tests/ReproducibilityTests.cs Converts conditional tests to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.Reproducibility.Tests/Microsoft.DotNet.Reproducibility.Tests.csproj Removes VSTest-specific project properties.
test/Microsoft.DotNet.Installer.Tests/Microsoft.DotNet.Installer.Tests.csproj Removes VSTest-specific project properties.
test/Microsoft.DotNet.Installer.Tests/LinuxInstallerTests.cs Converts conditional facts/theories to xUnit v3 SkipUnless usage.
test/Microsoft.DotNet.Installer.Tests/DockerHelper.cs Updates ITestOutputHelper namespace usage for xUnit v3.
test/Directory.Build.props Defines MTP test app settings and standardizes report generation + results dir.
src/global.json Adds a global.json under src/ (currently empty).
NuGet.config Adds test-tools feed for early-access Microsoft.Testing.Platform packages.
global.json Sets MTP as the dotnet test runner and pins SDK selection behavior.
eng/Versions.props Removes VSTest runner setting and pins MicrosoftTestingPlatformVersion.
eng/Tests.targets Removes VSTest-overriding Test target.
eng/pipelines/templates/stages/vmr-license-scan.yml Updates dotnet test invocation to MTP/xUnit v3 filtering/output args.
eng/pipelines/templates/jobs/sdk-diff-tests.yml Updates dotnet test invocation to MTP/xUnit v3 filtering/output args.
eng/build.ps1 Removes VSTest hang workaround env var for test runs.
Directory.Packages.props Switches CPM entries to xUnit v3 and pins MTP MSBuild integration forward.
Directory.Build.props Disables Arcade test framework integration and keeps repo-wide compiler settings.
build.sh Removes VSTest-related env var workarounds for test runs.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 52/52 changed files
  • Comments generated: 1

Comment thread src/global.json Resolved
Comment thread global.json Resolved
Comment thread global.json Resolved
xUnit.net v3 requires Skip to be set whenever SkipWhen or SkipUnless is used;
without it every conditional test fails at runtime with 'You must set Skip when
you set SkipUnless or SkipWhen ... to set the message for conditional skips'
instead of being skipped. This only surfaces once a condition actually triggers
a skip, which is why it showed up in CI rather than locally.

Also turn on the two Microsoft.Testing.Platform reporting switches. Both default
to the quiet setting, so a failing run logged a single error pointing at a log
file that isn't published, leaving no way to tell which tests failed or why from
the build log alone.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
@ViktorHofer

Copy link
Copy Markdown
Member Author

we can also try to just not set Skip, I think xunit will record the skip reason regardless.

@akoeplinger turns out the Skip message is actually required otherwise xunit throws at run time.

ViktorHofer and others added 3 commits August 7, 2026 15:46
When --with-sdk points the build at an SDK whose version differs from the one
pinned in the root global.json, the build fails during toolset initialization
with 'A compatible .NET SDK was not found' before anything gets built: the SDK
resolver reads sdk/version and Arcade's tools.sh reads tools/dotnet, and neither
matches the SDK actually in use.

Rewrite both entries to the custom SDK's version, mirroring what the
UpdateGlobalJsonVersions target already does for each repository underneath.
Both build.sh and prep-source-build.sh route --with-sdk through
source_only_toolset_init, so this covers both.

Each substitution is scoped to the object owning the key so unrelated entries
are left alone.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
TestingPlatformShowTestsFailure alone gives the failure detail: the task only
logs errors in response to a failed test, so a passing run prints the same
single-line summary it did before. TestingPlatformCaptureOutput=false instead
routes every line the test process writes through MSBuild logging regardless of
the outcome, which isn't needed to diagnose failures.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
--output Detailed was carried over as a translation of the old VSTest
'console;verbosity=detailed' logger, but Microsoft.Testing.Platform already
reports the assertion message and stack trace of a failing test at its default
level. The option only adds a line per passing test, which for these runs is
noise.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 761287f0-d9eb-4740-974e-b168dab091a8
@ViktorHofer

ViktorHofer commented Aug 7, 2026 •

Copy link
Copy Markdown
Member Author

OK this PR is now officially ready and will turn green :) I expect minor time savings but more importantly a modern UX due to xunit v3 + MTP.

@ViktorHofer
ViktorHofer merged commit 64a2986 into main Aug 10, 2026
9 of 11 checks passed
@ViktorHofer
ViktorHofer deleted the ViktorHofer/test-xunit-v3-mtp branch August 10, 2026 07:11
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.

5 participants