Skip to content

Migrate Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests to MSTest.Sdk on MTP#54758

Open
Evangelink wants to merge 1 commit into
dotnet:mainfrom
Evangelink:evangelink/mstest-mtp-templateengine-authoring-tasks
Open

Migrate Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests to MSTest.Sdk on MTP#54758
Evangelink wants to merge 1 commit into
dotnet:mainfrom
Evangelink:evangelink/mstest-mtp-templateengine-authoring-tasks

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Migrates the Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests project from xUnit v3 to MSTest.Sdk on Microsoft.Testing.Platform (MTP).

Changes

  • Switch the project SDK to MSTest.Sdk so MSTest 4.x + MTP defaults are picked up automatically (no more Verify.XunitV3 / xUnit v3 runner).
  • Replace ITestOutputHelper constructor injection with an MSTest TestContext property. Test log output now flows through a small TestContextLogger : ILogger adapter into TestContext.WriteLine.
  • Switch the calls to Microsoft.TemplateEngine.CommandUtils.DotnetCommand to its existing ILogger overload, so the test code itself no longer depends on xUnit's ITestOutputHelper.
  • Convert xUnit attributes/assertions to MSTest equivalents ([Fact] -> [TestMethod], Assert.True/False/Equal -> Assert.IsTrue/IsFalse/AreEqual).

Shared CommandUtils handling

The shared src/TemplateEngine/Tools/Shared/Microsoft.TemplateEngine.CommandUtils/ sources are still consumed by other in-tree xUnit projects, so they are left untouched. Two minimal accommodations are made in this test project only:

  1. A GlobalUsings.cs with global using ITestOutputHelper = Xunit.ITestOutputHelper; so the included TestCommand.cs compiles without dragging the full Xunit global using (which would clash with MSTest's Assert). The Xunit type is reachable transitively (compile only) via the Microsoft.TemplateEngine.TestHelper ProjectReference.
  2. A local CommandResultAssertions.MSTest.cs that mirrors the shared assertions class using MSTest's Assert.IsTrue / IsFalse / IsNotNull, plus a <Compile Remove="..."> to exclude the shared xUnit-based copy from this project's compile.

Verification

  • ./build.cmd -projects test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests.csproj succeeds with 0 warnings / 0 errors.
  • The produced executable is an MTP host; --list-tests discovers all 6 tests (CanRunTask, CanRunTaskSelectedLangs, CanRunTaskSelectedTemplates, CanRunTaskAndDetectError, CanRunValidateTask_OnError, CanRunValidateTask_OnInfo).
  • Runtime assertion failures flow back through CommandResultAssertions.Pass() -> Assert.IsTrue with proper file/line information, confirming MSTest is the active runner.

Part of the larger MSTest migration effort.

cc @Evangelink

…MSTest.Sdk on MTP

- Switch SDK to MSTest.Sdk so the project picks up Microsoft.Testing.Platform (MTP) and MSTest 4.x defaults instead of xUnit v3 + VSTest.

- Replace ITestOutputHelper constructor injection with an MSTest TestContext property and forward log output to TestContext.WriteLine through a small TestContextLogger : ILogger adapter.

- Use the existing DotnetCommand(ILogger, ...) overload from Microsoft.TemplateEngine.CommandUtils so we no longer take a runtime dependency on xUnit's ITestOutputHelper from the test code itself.

- Convert xUnit attributes/assertions to MSTest equivalents ([Fact] -> [TestMethod], Assert.True/False/Equal -> Assert.IsTrue/IsFalse/AreEqual).

- The shared Tools/Shared/Microsoft.TemplateEngine.CommandUtils sources still reference xUnit's ITestOutputHelper (consumed by other in-tree xUnit projects). Add a minimal 'global using ITestOutputHelper = Xunit.ITestOutputHelper;' alias so the included file compiles without dragging the full Xunit global using (which would clash with MSTest's Assert).

- Provide a local MSTest-friendly copy of CommandResultAssertions (CommandResultAssertions.MSTest.cs) and exclude the shared xUnit-based one from compile in this project only. The shared file is left untouched for the other xUnit consumers.
Copilot AI review requested due to automatic review settings June 13, 2026 14:40

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 Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests project from xUnit v3 to MSTest.Sdk (Microsoft.Testing.Platform), including replacing xUnit-specific logging/assertions with MSTest equivalents while keeping shared CommandUtils sources usable.

Changes:

  • Switch test project SDK to MSTest.Sdk and remove xUnit/Verify package references.
  • Replace ITestOutputHelper logging with TestContext + ILogger adapter (TestContextLogger) and use DotnetCommand(ILogger, ...).
  • Add MSTest-compatible CommandResultAssertions implementation and isolate remaining xUnit type usage via a minimal global alias.
Show a summary per file
File Description
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests.csproj Switch to MSTest.Sdk, remove xUnit/Verify packages, and adjust compilation to exclude xUnit-based shared assertions.
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/LocalizeTemplateTests.cs Convert xUnit tests to MSTest, including assertions and logging.
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/ValidateTemplatesTests.cs Convert xUnit tests to MSTest and route DotnetCommand logging through ILogger.
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/TestContextLogger.cs Add an ILogger implementation that forwards messages to TestContext.WriteLine.
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/GlobalUsings.cs Add a minimal alias for ITestOutputHelper to keep shared sources compiling without pulling in xUnit globals.
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/CommandResultAssertions.MSTest.cs Add MSTest-friendly mirror of shared CommandResultAssertions to avoid Assert API mismatches.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 1

Comment on lines 3 to 6
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
@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

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).

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.

2 participants