Migrate remaining xUnit test projects to MSTest.Sdk on MTP - #54976
Merged
Merged
Conversation
Migrates the three test projects that still used xUnit (v3) to MSTest.Sdk on Microsoft.Testing.Platform, following the pattern established by the sibling migration PRs (#54883, #54862, #54904): - test/Microsoft.NET.Build.Containers.IntegrationTests - test/TemplateEngine/.../TemplateVerifier.IntegrationTests - test/TemplateEngine/.../TemplateVerifier.UnitTests Verify.XunitV3 blocker (the two TemplateVerifier projects): The TemplateVerifier tool''s VerificationEngine drives snapshot verification through Verify.XunitV3 by default, which resolves the running test from xUnit''s ambient context and fails under MSTest (TestContext.TestMethod is null). Added a pluggable static VerificationEngine.DirectoryVerifier hook (with a NoInlining DefaultVerifyDirectory that keeps the xUnit reference off the default path) so MSTest consumers route directory verification to VerifyMSTest.Verifier.VerifyDirectory. Each migrated project wires this via a ModuleInitializer (VerifyDirectoryInitializer) and marks its snapshot classes [UsesVerify]; tests reference Verify.MSTest instead of Verify.XunitV3. test/TemplateEngine/Directory.Build.props now references Microsoft.NET.TestFramework.MSTest for UsingMSTestSdk projects (and keeps the xUnit framework for the rest), and sets SolutionDir/SolutionName so Verify''s solution auto-discovery does not warn under warnaserror. Containers.IntegrationTests: custom xUnit Docker Fact/Theory attributes became MSTest ConditionBaseAttribute gates (DockerUnavailableCondition, PodmanCliCondition, ContainerdStoreUnavailableCondition, DockerSupportsArchCondition); collection definitions became [DoNotParallelize]; ITestOutputHelper injection became SdkTest.Log; [Fact]/[Theory]/[InlineData] -> [TestMethod]/[DataRow]; assertions ported to MSTest. All three projects build cleanly (0 errors, 0 warnings). Tests were not run as part of this change, matching the sibling migration PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs
…tests Resolve build failures surfaced after migrating Microsoft.NET.Build.Containers.IntegrationTests to MSTest.Sdk: - MSTEST0037: use Assert.IsGreaterThan / Assert.AreEqual / Assert.IsNotEmpty / Assert.Contains instead of Assert.IsTrue - MSTEST0049: pass TestContext.CancellationToken to GetAsync/Task.Delay overloads - MSTEST0054: use TestContext.CancellationToken instead of TestContext.CancellationTokenSource.Token - MSTEST0052: drop redundant DynamicDataSourceType.Method argument - CS8604: null-forgive errors[0] after ContainsSingle assertion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…assignment After merging main, the new MSTest consumers added on main assign 'VerifyMSTest.Verifier.VerifyDirectory' to VerificationEngine.DirectoryVerifier as a method group. That verifier returns SettingsTask, which is convertible to Task only via a user-defined conversion (SettingsTask does not derive from Task), so the method-group conversion to a Task-returning delegate failed with CS0407. Change VerifyDirectoryDelegate (and DefaultVerifyDirectory) to return SettingsTask so both the MSTest and xUnit Verifier.VerifyDirectory method groups match exactly, and update PublicAPI.Unshipped.txt accordingly. SettingsTask lives in the Verify core (VerifyTests) assembly, so the lazy-load isolation of the xUnit adapter in DefaultVerifyDirectory is preserved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the remaining xUnit (v3) test projects in the SDK repo to MSTest.Sdk on Microsoft.Testing.Platform, and updates the shipping TemplateVerifier tool to support a pluggable Verify directory-verifier so snapshot verification can run under MSTest (via Verify.MSTest) instead of relying on xUnit ambient context.
Changes:
- Move TemplateVerifier Unit/Integration test projects to
MSTest.Sdk+Verify.MSTest, wiring snapshot directory verification viaModuleInitializer. - Migrate
Microsoft.NET.Build.Containers.IntegrationTestsfrom xUnit to MSTest, replacing xUnit attributes/fixtures/output with MSTest patterns and condition attributes. - Add
VerificationEngine.DirectoryVerifierhook (and public API surface) to allow non-xUnit test frameworks to supply a framework-specificVerifyDirectoryimplementation.
Show a summary per file
| File | Description |
|---|---|
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests/VerifyDirectoryInitializer.cs | Adds module initializer to route directory verification through Verify.MSTest. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests/VerificationEngineTests.cs | Converts tests to MSTest + Verify.MSTest and uses MSTest cancellation token/logging patterns. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests/TestContextLogger.cs | Adds MSTest TestContext-backed ILogger adapter for test output. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests.Shared.props | Adjusts shared package references for the migrated UnitTests project. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests.csproj | Switches project SDK to MSTest.Sdk and adds Verify.MSTest reference. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests/GlobalUsings.cs | Adds global aliases to avoid ambiguity with transitively referenced xUnit/Verify types. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/VerifyDirectoryInitializer.cs | Adds module initializer to route directory verification through Verify.MSTest. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/VerificationEngineTests.cs | Converts tests to MSTest + Verify.MSTest and uses MSTest cancellation token/logging patterns. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/TestContextLogger.cs | Adds MSTest TestContext-backed ILogger adapter for test output. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/TemplateEngineSamplesTest.cs | Converts data-driven snapshot tests to MSTest + Verify.MSTest. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests.csproj | Switches project SDK to MSTest.Sdk and adds Verify.MSTest reference. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/GlobalUsings.cs | Adds global aliases to avoid ambiguity with transitively referenced xUnit/Verify types. |
| test/TemplateEngine/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests/ExampleTemplateTest.cs | Converts snapshot tests to MSTest + Verify.MSTest. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/TargetsTests.cs | Migrates to MSTest and converts MemberData/Theory usage to DynamicData-based MSTest data tests. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/RegistryTests.cs | Migrates to MSTest and routes logging via SdkTest.Log/TestLoggerFactory. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/ProjectInitializer.cs | Updates assertions for MSTest equivalents. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/ParseContainerPropertiesTests.cs | Migrates to MSTest and updates asserts (including collection/message checks). |
| test/Microsoft.NET.Build.Containers.IntegrationTests/PackageTests.cs | Migrates basic package validation tests from xUnit to MSTest. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/MSBuildCollection.cs | Removes xUnit collection-based serialization helper. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/Microsoft.NET.Build.Containers.IntegrationTests.csproj | Switches project SDK to MSTest.Sdk and updates TestFramework references/usings. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/LayerEndToEndTests.cs | Migrates end-to-end layer tests to MSTest and updates assertions. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs | Migrates Docker end-to-end tests to MSTest, adds condition-based gating, and updates logging/cancellation. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerTestsFixture.cs | Removes xUnit fixture used for Docker registry lifecycle. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerTestsCollection.cs | Removes xUnit collection definition used for Docker test grouping/serialization. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerSupportsArchHelper.cs | Removes xUnit DataAttribute-based per-row arch gating helper. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerRegistryTests.cs | Migrates Docker registry tests to MSTest and updates logging/assertions. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerIsAvailableAndSupportsArchTheory.cs | Removes xUnit TheoryAttribute-based Docker+arch gating attribute. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerIsAvailableAndSupportsArchFact.cs | Removes xUnit FactAttribute-based Docker+arch gating attribute. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerAvailableUtils.cs | Adds MSTest condition attributes for Docker availability / containerd store / arch support. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/DockerAvailableAttributes.cs | Removes xUnit-specific Docker availability attributes now that project is MSTest. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/CreateNewImageTests.cs | Migrates task-level Docker tests to MSTest, updates local-registry selection and assertions. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/CreateImageIndexTests.cs | Migrates multi-arch image index tests to MSTest and updates registry/logging wiring. |
| test/Microsoft.NET.Build.Containers.IntegrationTests/ArchiveFileRegistryTests.cs | Migrates archive-output registry tests to MSTest and updates data-driven patterns/assertions. |
| src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs | Introduces a public DirectoryVerifier hook and a default non-inlined xUnit verifier path. |
| src/TemplateEngine/Tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/PublicAPI.Unshipped.txt | Records new public API surface for the TemplateVerifier tool. |
Copilot's findings
- Files reviewed: 35/35 changed files
- Comments generated: 4
…Data Under xUnit, TheoryData<...,string[]> passed the trailing string[] as the params array (xUnit does not unfold params). MSTest's DynamicData DOES unfold a params parameter: it took the row's 4th element (a nested string[]) and tried to store it into a string slot of a freshly built string[], throwing 'Object cannot be stored in an array of this type' at runtime for all 8 cases. Removing 'params' maps the row's 4th element (string[]) directly to the parameter, matching MSTest DynamicData positional binding. The test body uses the argument as a plain collection, so behavior is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Contributor
Evangelink
enabled auto-merge
June 29, 2026 13:47
JeremyKuhne
approved these changes
Jun 29, 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.
Migrates the three test projects that still used xUnit (v3) to
MSTest.Sdkon Microsoft.Testing.Platform (MTP), following the pattern established by the sibling migration PRs #54883, #54862, and #54904. With these, every remaining xUnit test project covered by this effort is now on MSTest.Projects migrated
test/Microsoft.NET.Build.Containers.IntegrationTeststest/TemplateEngine/.../Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTeststest/TemplateEngine/.../Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTestsResolving the Verify.XunitV3 blocker (why #54883 skipped the TemplateVerifier projects)
The shared
TemplateVerifiertool'sVerificationEnginedrives snapshot verification throughVerify.XunitV3by default. That adapter resolves the running test from xUnit's ambient context, which is unavailable under MSTest and fails at runtime withTestContext.TestMethod is null. That is precisely why #54883 left these two projects on xUnit.To resolve it properly (rather than leave them on xUnit), this PR adds a pluggable hook to the shipping tool:
VerificationEngine.DirectoryVerifier— an optionalstaticoverride of the directory-verification entry point. When unset, the built-in xUnit verifier is used (kept behind a[MethodImpl(NoInlining)]DefaultVerifyDirectoryso theVerify.XunitV3reference stays off the path when an override is supplied).PublicAPI.Unshipped.txtupdated accordingly.ModuleInitializer(VerifyDirectoryInitializer) that routes verification toVerifyMSTest.Verifier.VerifyDirectory, marks its snapshot test classes[UsesVerify], and referencesVerify.MSTestinstead ofVerify.XunitV3.Infra
test/TemplateEngine/Directory.Build.propsnow referencesMicrosoft.NET.TestFramework.MSTestforUsingMSTestSdkprojects (keeping the xUnit framework for the rest), and setsSolutionDir/SolutionNameso Verify's solution auto-discovery doesn't emit a warning thatwarnaserrorwould promote to an error in the Helix test build.Containers.IntegrationTests highlights
Docker*Fact/Docker*Theoryattribute subclasses → MSTestConditionBaseAttributegates (DockerUnavailableCondition,PodmanCliCondition,ContainerdStoreUnavailableCondition,DockerSupportsArchCondition), mirroring the already-migratedMicrosoft.NET.Build.Containers.UnitTestssibling.[CollectionDefinition]/[Collection](incl.DisableParallelization) →[DoNotParallelize]on the affected classes (the empty collection/fixture holders were removed; the deadDockerTestsFixturewas deleted).ITestOutputHelperinjection →SdkTest.Log;[Fact]/[Theory]/[InlineData]→[TestMethod]/[DataRow]; assertions ported to MSTest (Assert.Throws<T>→Assert.ThrowsExactly<T>, etc.).Parallelization
No
[assembly: Parallelize]was added;[DoNotParallelize]is applied to the formerly-collection / shared-state / snapshot classes, matching the sibling-PR convention.Validation
All three projects build cleanly — 0 errors, 0 warnings — against the repo-local SDK. Tests were not run as part of this change, matching the sibling migration PRs (which state the same).
Open items / blockers for reviewers
DirectoryVerifierhook toVerificationEngine. They will need to be reconciled at merge; the implementations are functionally equivalent.DockerSupportsArchInlineData(CanPackageForAllSupportedContainerRIDs) is already[Ignore]d (Enable containerd to re-enable multi-arch containers tests #49300), so its rows were converted to plain[DataRow]s with the arch prepended and the per-rowSkiptext dropped. If that test is ever re-enabled, the per-arch runtime gating will need to be reintroduced (e.g. viaAssert.Inconclusive).Microsoft.NET.TestFramework,Microsoft.TemplateEngine.TestHelper) were not modified.Part of the xUnit → MSTest migration effort.