Skip to content

Migrate remaining xUnit test projects to MSTest.Sdk on MTP - #54976

Merged
Evangelink merged 7 commits into
mainfrom
evangelink-migrate-remaining-xunit-projects
Jun 29, 2026
Merged

Evangelink merged 7 commits into
mainfrom
evangelink-migrate-remaining-xunit-projects

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Migrates the three test projects that still used xUnit (v3) to MSTest.Sdk on 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.IntegrationTests
  • test/TemplateEngine/.../Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests
  • test/TemplateEngine/.../Microsoft.TemplateEngine.Authoring.TemplateVerifier.UnitTests

Resolving the Verify.XunitV3 blocker (why #54883 skipped the TemplateVerifier projects)

The shared TemplateVerifier tool's VerificationEngine drives snapshot verification through Verify.XunitV3 by default. That adapter resolves the running test from xUnit's ambient context, which is unavailable under MSTest and fails at runtime with TestContext.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 optional static override of the directory-verification entry point. When unset, the built-in xUnit verifier is used (kept behind a [MethodImpl(NoInlining)] DefaultVerifyDirectory so the Verify.XunitV3 reference stays off the path when an override is supplied). PublicAPI.Unshipped.txt updated accordingly.
  • Each migrated project installs a ModuleInitializer (VerifyDirectoryInitializer) that routes verification to VerifyMSTest.Verifier.VerifyDirectory, marks its snapshot test classes [UsesVerify], and references Verify.MSTest instead of Verify.XunitV3.

Note: this overlaps conceptually with #54904, which adds an equivalent hook on an older base. Current main already carries the newer CustomDirectoryVerifier content-fetcher mechanism; this change layers the DirectoryVerifier static hook on top of it for the default verification path.

Infra

  • test/TemplateEngine/Directory.Build.props now references Microsoft.NET.TestFramework.MSTest for UsingMSTestSdk projects (keeping the xUnit framework for the rest), and sets SolutionDir/SolutionName so Verify's solution auto-discovery doesn't emit a warning that warnaserror would promote to an error in the Helix test build.

Containers.IntegrationTests highlights

  • Custom xUnit Docker*Fact/Docker*Theory attribute subclasses → MSTest ConditionBaseAttribute gates (DockerUnavailableCondition, PodmanCliCondition, ContainerdStoreUnavailableCondition, DockerSupportsArchCondition), mirroring the already-migrated Microsoft.NET.Build.Containers.UnitTests sibling.
  • [CollectionDefinition]/[Collection] (incl. DisableParallelization) → [DoNotParallelize] on the affected classes (the empty collection/fixture holders were removed; the dead DockerTestsFixture was deleted).
  • Constructor ITestOutputHelper injection → 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

  • Shipping-tool change overlaps with Migrate dotnet-new.IntegrationTests to MSTest.Sdk on MTP #54904. Both add a DirectoryVerifier hook to VerificationEngine. They will need to be reconciled at merge; the implementations are functionally equivalent.
  • Arch-conditional data semantics. The one method using per-row 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-row Skip text dropped. If that test is ever re-enabled, the per-arch runtime gating will need to be reintroduced (e.g. via Assert.Inconclusive).
  • Shared xUnit-coupled helper libraries (Microsoft.NET.TestFramework, Microsoft.TemplateEngine.TestHelper) were not modified.

Part of the xUnit → MSTest migration effort.

Evangelink and others added 3 commits June 25, 2026 15:08
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>
@Evangelink
Evangelink marked this pull request as ready for review June 26, 2026 10:42
@Evangelink
Evangelink requested a review from a team as a code owner June 26, 2026 10:42
Copilot AI review requested due to automatic review settings June 26, 2026 10:42

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 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 via ModuleInitializer.
  • Migrate Microsoft.NET.Build.Containers.IntegrationTests from xUnit to MSTest, replacing xUnit attributes/fixtures/output with MSTest patterns and condition attributes.
  • Add VerificationEngine.DirectoryVerifier hook (and public API surface) to allow non-xUnit test frameworks to supply a framework-specific VerifyDirectory implementation.
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

Evangelink and others added 2 commits June 26, 2026 16:26
…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>
@Evangelink

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

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

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Addressed in 1705d50. I merged the latest main, resolved the VerificationEngine conflict, and verified the affected projects still build cleanly.

@Evangelink
Evangelink merged commit 39f346b into main Jun 29, 2026
24 checks passed
@Evangelink
Evangelink deleted the evangelink-migrate-remaining-xunit-projects branch June 29, 2026 17:15
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 30, 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.

4 participants