Skip to content

Add Microsoft.NET.TestFramework.MSTest infra to onboard the test suite to MSTest - #54769

Merged
Evangelink merged 3 commits into
dotnet:mainfrom
Evangelink:evangelink/mstest-test-framework-infra
Jun 16, 2026
Merged

Evangelink merged 3 commits into
dotnet:mainfrom
Evangelink:evangelink/mstest-test-framework-infra

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal

Foundational infrastructure to onboard the entire dotnet/sdk test suite to MSTest on Microsoft.Testing.Platform (MTP).

The blocker to a full migration is the shared Microsoft.NET.TestFramework project: it is coupled to xUnit and is referenced by ~53 test projects, so none of them can move to MSTest until the framework offers an MSTest-compatible surface.

Key insight: the xUnit coupling is shallow

The coupling is concentrated in ~17 of ~99 files:

  • the Attributes/* discovery attributes (PlatformSpecificFact, *MSBuildOnly*, Requires*, …), and
  • two IMessageSink-based logger bridges (SharedTestOutputHelper.cs, TestLoggerFactory.cs).

The remaining ~82 runner-agnostic files (~6,500 LOC — all Command classes, TestAsset/TestAssetsManager, assertions, project construction, SdkTest) reference the test-output sink only through the unqualified name ITestOutputHelper, supplied today via a global <Using Include=""Xunit"" />.

What this PR does

Adds a new test/Microsoft.NET.TestFramework.MSTest project that link-shares the ~82 agnostic source files from the legacy framework (zero duplication) and supplies the MSTest-specific pieces locally:

File Role
ITestOutputHelper.cs Own interface, shape-identical to xUnit v3's, so the shared sources bind to it instead of Xunit.ITestOutputHelper
TestContextOutputHelper.cs MSTest TestContext-backed implementation
SdkTest.cs MSTest base class (TestContext property instead of constructor injection)
TestLoggerFactory.cs MSTest logger factory (reuses the shared XunitLoggerProvider)

Supporting changes:

  • InternalsVisibleTo grants for the new assembly from Microsoft.DotNet.Cli.Utils and Microsoft.DotNet.InternalAbstractions (the link-shared Mock/* helpers use their internals).
  • Registered in sdk.slnx.

The namespace is kept as Microsoft.NET.TestFramework so that, once every consumer has migrated, the legacy project can be deleted and this one renamed with no source churn.

Validation

Builds clean on net11.0 and net472 (0 warnings / 0 errors). No existing project is touched, so the 53 current xUnit consumers are unaffected.

Onboarding roadmap (follow-ups)

  1. MSTest conditional attributes: [OSCondition] (MSTest 4.3) covers OS gating; the MSBuild variants (CoreMSBuildOnly / FullMSBuildOnly / RequiresMSBuildVersion) need ConditionBaseAttribute subclasses.
  2. Provide an MSTest AspNetSdkTest base.
  3. Migrate consumer projects in batches (leaf/simple first), pointing each at this project instead of the xUnit framework.
  4. When all consumers are migrated: delete the legacy Microsoft.NET.TestFramework and rename this project.

Co-authored-by: Copilot [email protected]

Copilot AI review requested due to automatic review settings June 15, 2026 11:18

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

This PR introduces a new Microsoft.NET.TestFramework.MSTest infrastructure project to enable migrating dotnet/sdk test projects from xUnit to MSTest (MTP) by link-sharing the runner-agnostic portions of the existing Microsoft.NET.TestFramework while providing MSTest-specific replacements (output abstraction, base test class, logger factory).

Changes:

  • Added test/Microsoft.NET.TestFramework.MSTest project that link-shares most sources from the legacy framework and supplies MSTest-specific implementations (ITestOutputHelper, TestContextOutputHelper, SdkTest, TestLoggerFactory).
  • Added InternalsVisibleTo entries so the new MSTest framework can access required internals used by link-shared helpers.
  • Registered the new project in sdk.slnx.
Show a summary per file
File Description
test/Microsoft.NET.TestFramework.MSTest/TestLoggerFactory.cs MSTest logger factory producing ILogger instances backed by test output and console logging.
test/Microsoft.NET.TestFramework.MSTest/TestContextOutputHelper.cs MSTest TestContext-backed implementation of the shared ITestOutputHelper abstraction.
test/Microsoft.NET.TestFramework.MSTest/SdkTest.cs MSTest base class for SDK tests using TestContext rather than ctor injection.
test/Microsoft.NET.TestFramework.MSTest/Microsoft.NET.TestFramework.MSTest.csproj New project file configuring link-sharing of runner-agnostic sources and MSTest dependencies.
test/Microsoft.NET.TestFramework.MSTest/ITestOutputHelper.cs Local ITestOutputHelper interface to keep shared sources runner-agnostic.
src/Cli/Microsoft.DotNet.InternalAbstractions/Properties/Properties.cs Grants internals access to the new MSTest framework assembly.
src/Cli/Microsoft.DotNet.Cli.Utils/Properties/AssemblyInfo.cs Grants internals access to the new MSTest framework assembly.
sdk.slnx Adds the new MSTest framework project to the solution.

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 2

@Evangelink
Evangelink enabled auto-merge (squash) June 15, 2026 12:07
Evangelink and others added 3 commits June 16, 2026 09:02
…cation)

Introduces an MSTest-flavored counterpart of the xUnit-coupled
Microsoft.NET.TestFramework so SDK test projects can migrate to MSTest on
Microsoft.Testing.Platform. This is the foundational unlock for onboarding the
whole test suite (~53 projects reference the shared framework).

The xUnit coupling of the legacy framework is concentrated in ~17 of ~99 files
(the Attributes/* discovery attributes and two IMessageSink-based logger
bridges). The remaining ~82 runner-agnostic files reference the test output sink
only through the unqualified name ITestOutputHelper. This project therefore
LINK-SHARES those agnostic sources (zero duplication) and supplies the
MSTest-specific pieces locally:

* ITestOutputHelper       - own interface (shape-identical to xUnit v3's) so the
                            shared sources bind to it instead of Xunit.ITestOutputHelper
* TestContextOutputHelper - MSTest TestContext-backed implementation
* SdkTest                 - MSTest base class (TestContext property instead of
                            constructor injection)
* TestLoggerFactory       - MSTest logger factory (reuses the shared XunitLoggerProvider)

The namespace is kept as Microsoft.NET.TestFramework so that, once every consumer
has migrated, the legacy project can be deleted and this one renamed with no
source churn.

Also grants InternalsVisibleTo to the new assembly from
Microsoft.DotNet.Cli.Utils and Microsoft.DotNet.InternalAbstractions (the
link-shared Mock/* helpers use their internals), and registers the project in
sdk.slnx.

Builds clean on net11.0 and net472.

Co-authored-by: Copilot <[email protected]>
Switches the project from plain Microsoft.NET.Sdk + a MSTest.TestFramework
PackageReference (VersionOverride hack) to Sdk="MSTest.Sdk" with
IsTestApplication=false.

Per MSTest.Sdk's ClassicEngine.targets, the "Core" MSTest.TestFramework reference
is unconditional, while MSTest.TestAdapter, the MSTest runner,
Microsoft.Testing.Platform and the testing extensions are gated on
IsTestApplication=='true'. So a test *library* gets the framework (with its
version kept in sync with the SDK) and none of the test-application machinery.

Also drops the now-redundant AwesomeAssertions PackageReference and FluentAssertions
global using: UsingMSTestSdk=true (set by MSTest.Sdk) makes
test/Directory.Build.targets provide both.

Verified: builds clean on net11.0 and net472; output contains no TestAdapter /
Microsoft.Testing.Platform / extensions assemblies.

Co-authored-by: Copilot <[email protected]>
- TestLoggerFactory: add a parameterless constructor (chaining to the
  TestContext? overload) to preserve the legacy 'new TestLoggerFactory()' usage
  and minimize source churn when consumers migrate; drop the unnecessary cast
  when chaining the TestContext? overload.
- TestContextOutputHelper: correct the misleading comment that claimed
  TestContext only exposes WriteLine - it exposes Write (no trailing newline),
  which is what the partial-write path intentionally uses.

Co-authored-by: Copilot <[email protected]>
@Evangelink
Evangelink force-pushed the evangelink/mstest-test-framework-infra branch from 416e47c to 60eecf8 Compare June 16, 2026 07:04
@Evangelink

Copy link
Copy Markdown
Member Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@Evangelink
Evangelink merged commit 8baae54 into dotnet:main Jun 16, 2026
25 checks passed
@Evangelink
Evangelink deleted the evangelink/mstest-test-framework-infra branch June 16, 2026 16:58
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
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.

3 participants