Migrate System.CommandLine.StaticCompletions.Tests to MSTest.Sdk#54729
Migrate System.CommandLine.StaticCompletions.Tests to MSTest.Sdk#54729Evangelink wants to merge 12 commits into
Conversation
|
Replaced the manual Also refreshed the related comments in |
|
Made The new (Applied to all 9 stacked PRs since they share these plumbing files.) |
|
Replaced the custom |
|
Also removed |
|
Round 3: moved The Using is now global for any test project ( Deviation from your literal suggestion: I left the |
There was a problem hiding this comment.
Pull request overview
Migrates selected test projects from xUnit to MSTest.Sdk / Microsoft.Testing.Platform (MTP) and updates the test/Helix infrastructure to correctly publish and execute MTP-based tests (including TRX emission where supported).
Changes:
- Migrate
System.CommandLine.StaticCompletions.Testsfrom xUnit/Verify.XunitV3 to MSTest/Verify.MSTest (switching output fromITestOutputHelpertoTestContext). - Teach the custom Helix work-item generation to detect MSTest.Sdk/MTP projects and invoke them via
dotnet exec(optionally enabling--report-trxwhen supported). - Adjust test-wide build configuration for MSTest.Sdk projects (global usings + AwesomeAssertions) and pin the MSTest.Sdk MSBuild SDK version in
global.json.
Show a summary per file
| File | Description |
|---|---|
| test/xunit-runner/XUnitRunner.targets | Captures MTP/TRX capability metadata from published test projects for Helix dispatching. |
| test/xunit-runner/XUnitPublish.targets | Adds MSBuild targets to surface UsingMSTestSdk and TRX-extension enablement as queryable outputs. |
| test/System.CommandLine.StaticCompletions.Tests/ZshShellProviderTests.cs | Converts test class/methods to MSTest attributes and uses TestContext for Verify logging. |
| test/System.CommandLine.StaticCompletions.Tests/VerifyExtensions.cs | Updates Verify helper to accept TestContext and write output via MSTest. |
| test/System.CommandLine.StaticCompletions.Tests/System.CommandLine.StaticCompletions.Tests.csproj | Switches project SDK to MSTest.Sdk and replaces Verify.XunitV3 with Verify.MSTest. |
| test/System.CommandLine.StaticCompletions.Tests/PowershellProviderTests.cs | Converts provider snapshot tests to MSTest + TestContext. |
| test/System.CommandLine.StaticCompletions.Tests/HelpExtensionsTests.cs | Converts pure assertion tests from [Fact] to [TestMethod]. |
| test/System.CommandLine.StaticCompletions.Tests/FishShellProviderTests.cs | Converts provider snapshot tests to MSTest + TestContext. |
| test/System.CommandLine.StaticCompletions.Tests/BashShellProviderTests.cs | Converts provider snapshot tests to MSTest + TestContext. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/Microsoft.DotNet.HotReload.Watch.Aspire.Tests.csproj | Switches this test project to MSTest.Sdk and trims unused dependencies. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireServerLauncherCliTests.cs | Converts CLI tests from xUnit to MSTest assertions/APIs. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireResourceLauncherCliTests.cs | Converts CLI tests from xUnit theory/data to MSTest DataRow patterns and assertions. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireHostLauncherTests.cs | Converts launcher unit tests to MSTest assertions. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireHostLauncherCliTests.cs | Converts CLI parsing tests to MSTest assertions/APIs. |
| test/HelixTasks/SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs | Adds MTP-aware command construction (dotnet exec) and conditional TRX support for Helix work items. |
| test/dotnet-watch.Tests/dotnet-watch.Tests.csproj | Adds a project reference needed for Aspire launcher integration tests. |
| test/dotnet-watch.Tests/Aspire/PipeUtilities.cs | Adds new named-pipe helper used by Aspire integration tests. |
| test/dotnet-watch.Tests/Aspire/AspireLauncherIntegrationTests.cs | Renames the test class to better reflect integration coverage. |
| test/Directory.Build.targets | Splits xUnit-only global usings from MSTest.Sdk needs; adds AwesomeAssertions for MSTest.Sdk projects. |
| src/Dotnet.Watch/Watch.Aspire/Properties/AssemblyInfo.cs | Extends InternalsVisibleTo to allow dotnet-watch.Tests to access internals. |
| global.json | Pins MSTest.Sdk MSBuild SDK version for consistent repo builds. |
| eng/dependabot/Packages.props | Adds Verify.MSTest to dependabot-managed package versions. |
Copilot's findings
- Files reviewed: 21/22 changed files
- Comments generated: 1
| string envPrefix; | ||
| if (IsPosixShell) | ||
| { | ||
| envPrefix = $"HELIX_WORK_ITEM_TIMEOUT={timeout} "; | ||
| } | ||
| else | ||
| { | ||
| envPrefix = $"set HELIX_WORK_ITEM_TIMEOUT={timeout}&& "; | ||
| } |
…n MTP
This is a pathfinder PR for migrating the test suite to MSTest on
Microsoft.Testing.Platform (MTP). Microsoft.DotNet.HotReload.Watch.Aspire.Tests
was chosen because it has no dependency on the shared Microsoft.NET.TestFramework
(which is xUnit-coupled and referenced by ~57 of 78 test projects), so it can
migrate in isolation without unblocking dependents first.
Changes:
* global.json: add MSTest.Sdk 4.3.0-preview.26307.5 to msbuild-sdks.
* test/Directory.Build.targets: gate the xUnit defaults
(TestRunnerName=XUnitV3, Using Include=Xunit, etc.) behind
$(UseMSTestSdk) != true, so MSTest.Sdk projects opt out cleanly.
* test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests:
- csproj now uses Sdk="MSTest.Sdk", sets UseMSTestSdk=true, references
AwesomeAssertions and only the Watch.Aspire project. MTP is on by default
via MSTest.Sdk (EnableMSTestRunner + TestingPlatformDotnetTestSupport).
- All 4 unit-test files converted from xUnit to MSTest attributes/asserts
([Fact]/[Theory] -> [TestMethod]/[DataRow], Assert.* equivalents,
Assert.IsInstanceOfType<T>, Assert.HasCount, Assert.IsEmpty).
- Local AssertEx.SequenceEqual<T> helper replaces the xUnit-coupled one
from HotReload.Test.Utilities.
* Move the 2 integration tests (AspireLauncherTests + PipeUtilities) to
test/dotnet-watch.Tests/Aspire/ so the Aspire.Tests project stays a pure
MSTest unit-test project. They keep xUnit because they depend on
WatchSdkTest, WatchableApp, [PlatformSpecificFact], ITestOutputHelper and
TestAssets from Microsoft.NET.TestFramework. AspireLauncherTests was
renamed to AspireLauncherIntegrationTests to reflect its new role.
* src/Dotnet.Watch/Watch.Aspire/Properties/AssemblyInfo.cs: grant
InternalsVisibleTo to dotnet-watch.Tests (needed by PipeUtilities, which
uses internal WatchStatusEvent).
* test/dotnet-watch.Tests/dotnet-watch.Tests.csproj: add ProjectReference to
Watch.Aspire (ExcludeAssets=Runtime) so the moved integration tests
compile.
Verification:
* Microsoft.DotNet.HotReload.Watch.Aspire.Tests builds with MSTest.Sdk and
all 58 unit tests pass under MTP (705 ms).
* test/dotnet-watch.Tests builds successfully with the moved files.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Bumps MSTest.Sdk to the latest internal preview to pick up the newest 4.3 assertion APIs (Assert.ContainsSingle, Assert.Contains for strings with the more natural (needle, haystack) signature, etc.). - Applies the assertion mapping flagged by the migrate-xunit-to-mstest skill in this repo (.github/skills/migrate-xunit-to-mstest, PR dotnet#54727): Assert.HasCount(1, x) -> Assert.ContainsSingle(x) (one occurrence in AspireResourceLauncherCliTests.cs) Verified: 58/58 tests still pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…parity Per reviewer feedback: MSTest 4.1.0+ exposes Assert.IsExactInstanceOfType<T>(value) which returns T and enforces exact-type semantics -- the proper equivalent of xUnit's Assert.IsType<T>(x). Assert.IsInstanceOfType<T> is the equivalent of xUnit's Assert.IsAssignableFrom<T> (assignable, not exact), which would be a silent semantic regression for the IsType<T> originals. All 39 occurrences across AspireHostLauncherCliTests.cs, AspireResourceLauncherCliTests.cs, AspireServerLauncherCliTests.cs, and AspireLauncherIntegrationTests.cs were originally Assert.IsType<T> in xUnit (verified against main), so all 39 are flipped to Assert.IsExactInstanceOfType<T>. Note: the migrate-xunit-to-mstest skill cheatsheet at .github/skills/migrate-xunit-to-mstest/references/mapping-cheatsheet.md recommends `Assert.IsInstanceOfType<T>` plus an extra typeof-check for exact-type semantics; that guidance predates IsExactInstanceOfType being available. Follow-up upstream (dotnet/skills) suggested. Verified: 58/58 Aspire tests still pass; dotnet-watch.Tests builds clean. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MSTest.Sdk already adds this as an implicit global using. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MSTest 4.3+ provides Assert.AreSequenceEqual for element-wise IEnumerable<T> compare with a nice diff message, so the project-local AssertEx helper is no longer needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…est/Directory.Build.targets Per @Evangelink: keep per-csproj boilerplate minimal. FluentAssertions is now a global using for any test project (gated on IsTestProject OR UsingMSTestSdk), and AwesomeAssertions is added as a PackageReference for MSTest.Sdk projects. xUnit projects continue to pick it up transitively via Microsoft.NET.TestFramework. The Microsoft.NET.TestFramework.* and Xunit usings remain gated on the xUnit branch (UsingMSTestSdk != true) because MSTest projects in this repo do not reference Microsoft.NET.TestFramework; making those usings global would fail with CS0246. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The recent `Helix dispatcher: gate --report-trx on TrxReport extension
being loaded` commit accidentally removed the ProjectReference to
Microsoft.DotNet.HotReload.Watch.Aspire from dotnet-watch.Tests.csproj
(introduced in the `Migrate Microsoft.DotNet.HotReload.Watch.Aspire.Tests
to MSTest.Sdk on MTP` commit to allow the moved AspireLauncherIntegrationTests
and PipeUtilities to compile).
Without that reference, the build fails with:
error CS0246: The type or namespace name 'WatchStatusEvent' could not be
found (are you missing a using directive or an assembly reference?)
[test/dotnet-watch.Tests/Aspire/PipeUtilities.cs]
Re-add the ProjectReference.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
12c0d1c to
86eaee2
Compare
Introduces an MSTest-flavored counterpart to the xUnit-based Microsoft.DotNet.HotReload.Test.Utilities so that test helpers that need MSTest's TestContext (e.g. TestLogger, TestLoggerFactory) can be shared across MSTest.Sdk test projects instead of being copy-pasted per project. This commit also migrates the inline TestLogger from Microsoft.DotNet.HotReload.Client.Tests to consume the shared project, which serves as the first reference consumer. Subsequent migration PRs (DeltaApplier.Tests, Containers.UnitTests) will adopt the same project reference instead of adding their own TestLogger/TestLoggerFactory copies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Switch SDK to MSTest.Sdk; set UseMSTestSdk=true to opt out of test/Directory.Build.targets xUnit defaults. - Replace [Fact] with [TestMethod]. - Replace Verify.XunitV3 with Verify.MSTest and use VerifyBase for MSTest TestContext wiring. - Replace ITestOutputHelper with TestContext. - Drop Microsoft.NET.TestFramework reference (not used). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Sdk)
MSTest.Sdk already sets $(UsingMSTestSdk)=true in its Sdk.props before
Directory.Build.props is evaluated, so the custom <UseMSTestSdk>true</UseMSTestSdk>
opt-in property is redundant. This change:
- Removes <UseMSTestSdk>true</UseMSTestSdk> from MSTest.Sdk csproj(s).
- Renames $(UseMSTestSdk) -> $(UsingMSTestSdk) in test/Directory.Build.targets
(the xUnit-defaults gating condition) and in xunit-runner/{XUnitPublish,XUnitRunner}.targets
(Helix MTP dispatcher detection).
MSTest.Sdk's Runner/Common.targets already sets `<IsPackable>false</IsPackable>` for every MSTest.Sdk project, so the per-project declaration is redundant.
…est/Directory.Build.targets Per @Evangelink: keep per-csproj boilerplate minimal. FluentAssertions is now a global using for any test project (gated on IsTestProject OR UsingMSTestSdk), and AwesomeAssertions is added as a PackageReference for MSTest.Sdk projects. xUnit projects continue to pick it up transitively via Microsoft.NET.TestFramework. The Microsoft.NET.TestFramework.* and Xunit usings remain gated on the xUnit branch (UsingMSTestSdk != true) because MSTest projects in this repo do not reference Microsoft.NET.TestFramework; making those usings global would fail with CS0246. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
86eaee2 to
b3561c0
Compare
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Summary
System.CommandLine.StaticCompletions.TeststoMSTest.Sdkon MTP.[Fact]tests with MSTest[TestMethod]and swapsITestOutputHelperforTestContext.Verify.XunitV3withVerify.MSTestand drops the unusedMicrosoft.NET.TestFrameworkproject reference.Note:
Verify.MSTest31.19.0 is used because 28.12.0 references pre-MSTest-4 assembly identities and failed at runtime under the pinned MSTest.Sdk 4.3 preview.Verification
Q:\src\sdk\.dotnet\dotnet.exe build test\System.CommandLine.StaticCompletions.Tests\System.CommandLine.StaticCompletions.Tests.csproj(0 warnings, 0 errors)Q:\src\sdk\.dotnet\dotnet.exe exec artifacts\bin\System.CommandLine.StaticCompletions.Tests\Debug\net11.0\System.CommandLine.StaticCompletions.Tests.dll(24 passed, 0 failed, 0 skipped)