Skip to content

Migrate dotnet.Tests to MSTest.Sdk on MTP - #54905

Merged
Evangelink merged 10 commits into
dotnet:mainfrom
Evangelink:evangelink/mstest-mtp-dotnettests
Jun 23, 2026
Merged

Evangelink merged 10 commits into
dotnet:mainfrom
Evangelink:evangelink/mstest-mtp-dotnettests

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Part of the ongoing xUnit -> MSTest.Sdk (MTP) test migration of the .NET SDK test suite, following the same pattern as the other open migration PRs (builds on the foundation merged in #54845).

The largest project (244 files): TheoryData becomes IEnumerable<object[]>, ~14 class fixtures and ~13 collections become static fixtures + [DoNotParallelize], and a small additive parameterless constructor is added to the shared EnvironmentSettingsHelper. Includes the InternalsVisibleTo grant this project needs and a target to strip the old xUnit framework dll pulled transitively by ComponentMocks.

Standard transformations: Microsoft.NET.Sdk -> MSTest.Sdk, the TestFramework project reference -> Microsoft.NET.TestFramework.MSTest, [Fact]/[Theory] -> [TestMethod], [InlineData] -> [DataRow], xUnit asserts -> MSTest (including the repo Recommended-mode idiomatic asserts), and ITestOutputHelper constructor injection removed in favour of the base SdkTest Log / TestContext.

Builds clean for the SDK target framework.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 19, 2026 18:26
@Evangelink
Evangelink requested review from a team as code owners June 19, 2026 18:26

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Evangelink and others added 2 commits June 20, 2026 09:39
…licationProtocolVersionTests to MSTest

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink
Evangelink enabled auto-merge June 20, 2026 08:34
…unFileTests_BuildCommands

The xUnit->MSTest migration incorrectly inserted [TestClass] into the
embedded lib.cs/module.cs source strings written by Build_Library_MultiTarget
and Build_Module, causing the file-based app build to fail with CS0246
(TestClassAttribute not found).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Evangelink and others added 6 commits June 20, 2026 15:14
ComponentMocks is compiled against the old xUnit Microsoft.NET.TestFramework and
loads it at runtime. The previous hack used ReferenceOutputAssembly=false plus a
ReferencePath removal, which dropped the assembly from deps.json, so ComponentMocks
threw FileNotFoundException for 'Microsoft.NET.TestFramework, Version=42.42.42.42'
at runtime (e.g. all Tool restore/install/update tests).

Reference the assembly directly so it stays in the runtime closure (output + deps.json),
and exclude it only from the C# compiler references (via ReferencePathWithRefAssemblies,
after FindReferenceAssembliesForReferences) to keep avoiding the CS0433 duplicate-type
conflict with Microsoft.NET.TestFramework.MSTest.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The xUnit->MSTest migration produced Assert.IsGreaterThan[OrEqualTo](value, lowerBound),
but the MSTest signature is IsGreaterThan[OrEqualTo](lowerBound, value) and asserts
value > / >= lowerBound. The reversed operands made the assertions fail (e.g.
sdkVersion.Major >= 10 was evaluated as 10 >= sdkVersion.Major). Swap them back.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify.MSTest's static Verify(...) requires [UsesVerify] on the test class so its
source generator emits the sealed-override TestContext setter that wires
Verifier.CurrentTestContext; otherwise the test throws 'TestContext is null'. Add
[UsesVerify] and make the class partial, and make SdkTest.TestContext virtual so the
generated override compiles.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The file was re-added with xUnit [Fact] attributes after the project was migrated to MSTest.Sdk, breaking the build (CS0246 Fact). Convert to [TestClass]/[TestMethod].

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink

Copy link
Copy Markdown
Member Author

/ba-g #54928 #54927

@Evangelink
Evangelink merged commit 0033305 into dotnet:main Jun 23, 2026
24 of 26 checks passed
@Evangelink
Evangelink deleted the evangelink/mstest-mtp-dotnettests branch June 23, 2026 08:16
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants