Migrate Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests to MSTest.Sdk on MTP#54758
Open
Evangelink wants to merge 1 commit into
Open
Conversation
…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.
Contributor
There was a problem hiding this comment.
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.Sdkand remove xUnit/Verify package references. - Replace
ITestOutputHelperlogging withTestContext+ILoggeradapter (TestContextLogger) and useDotnetCommand(ILogger, ...). - Add MSTest-compatible
CommandResultAssertionsimplementation 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> |
Member
Author
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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
Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTestsproject from xUnit v3 to MSTest.Sdk on Microsoft.Testing.Platform (MTP).Changes
MSTest.Sdkso MSTest 4.x + MTP defaults are picked up automatically (no moreVerify.XunitV3/ xUnit v3 runner).ITestOutputHelperconstructor injection with an MSTestTestContextproperty. Test log output now flows through a smallTestContextLogger : ILoggeradapter intoTestContext.WriteLine.Microsoft.TemplateEngine.CommandUtils.DotnetCommandto its existingILoggeroverload, so the test code itself no longer depends on xUnit'sITestOutputHelper.[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:GlobalUsings.cswithglobal using ITestOutputHelper = Xunit.ITestOutputHelper;so the includedTestCommand.cscompiles without dragging the fullXunitglobal using (which would clash with MSTest'sAssert). The Xunit type is reachable transitively (compile only) via theMicrosoft.TemplateEngine.TestHelperProjectReference.CommandResultAssertions.MSTest.csthat mirrors the shared assertions class using MSTest'sAssert.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.csprojsucceeds with 0 warnings / 0 errors.--list-testsdiscovers all 6 tests (CanRunTask,CanRunTaskSelectedLangs,CanRunTaskSelectedTemplates,CanRunTaskAndDetectError,CanRunValidateTask_OnError,CanRunValidateTask_OnInfo).CommandResultAssertions.Pass()->Assert.IsTruewith proper file/line information, confirming MSTest is the active runner.Part of the larger MSTest migration effort.
cc @Evangelink