Migrate dotnet.Tests to MSTest.Sdk on MTP - #54905
Merged
Evangelink merged 10 commits intoJun 23, 2026
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…licationProtocolVersionTests to MSTest Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
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>
Member
Author
YuliiaKovalova
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.