Repository navigation
Migrate containerize.UnitTests to MSTest.Sdk on MTP - #54723
Evangelink wants to merge 19 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR continues the test-suite migration to MSTest.Sdk on Microsoft.Testing.Platform (MTP) by opting specific test projects out of the repo-wide xUnit defaults and converting their tests/assertions accordingly, while also relocating Aspire integration coverage back into the xUnit-based dotnet-watch.Tests project.
Changes:
- Switch
containerize.UnitTests(and the stacked Aspire unit test project) toSdk="MSTest.Sdk"+UseMSTestSdk=true, removing xUnit-coupled test framework references. - Mechanically convert affected test sources from xUnit attributes/asserts to MSTest equivalents.
- Move Aspire integration tests/utilities into
dotnet-watch.Testsand add the needed project reference +InternalsVisibleTo.
Show a summary per file
| File | Description |
|---|---|
| global.json | Pins MSTest.Sdk under msbuild-sdks for Sdk resolution. |
| test/Directory.Build.targets | Gates xUnit defaults/usings behind UseMSTestSdk != true. |
| test/containerize.UnitTests/containerize.UnitTests.csproj | Migrates the project to MSTest.Sdk, opts out of xUnit defaults, drops Microsoft.NET.TestFramework reference. |
| test/containerize.UnitTests/ParserTests.cs | Converts tests to MSTest attributes/asserts (one remaining xUnit assert needs fixing). |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/Microsoft.DotNet.HotReload.Watch.Aspire.Tests.csproj | Migrates Aspire unit test project to MSTest.Sdk, adds MSTest + assertion global usings, drops xUnit-coupled test utilities reference. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AssertEx.cs | Adds local assertion helper to avoid dependency on xUnit-coupled shared utilities. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireServerLauncherCliTests.cs | Converts xUnit tests to MSTest. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireResourceLauncherCliTests.cs | Converts xUnit tests to MSTest (keeps assertion-library usage via Should() style). |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireHostLauncherTests.cs | Converts xUnit tests to MSTest. |
| test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/AspireHostLauncherCliTests.cs | Converts xUnit tests to MSTest. |
| test/dotnet-watch.Tests/dotnet-watch.Tests.csproj | Adds Watch.Aspire project reference needed for moved Aspire integration tests. |
| test/dotnet-watch.Tests/Aspire/PipeUtilities.cs | Adds a pipe helper for integration tests (missing using System.Text; needs fixing). |
| test/dotnet-watch.Tests/Aspire/AspireLauncherIntegrationTests.cs | Renames test class to reflect integration scope. |
| src/Dotnet.Watch/Watch.Aspire/Properties/AssemblyInfo.cs | Adds InternalsVisibleTo for dotnet-watch.Tests to access required internals. |
Copilot's findings
- Files reviewed: 13/14 changed files
- Comments generated: 1
580dad3 to
b37a18b
Compare
Same pattern as containerize.UnitTests (dotnet#54723). This project's single test file only uses xUnit Fact/Assert.Equal - no Microsoft.NET.TestFramework types - so the TestFramework ProjectReference can be dropped and the project switched to MSTest.Sdk in one self-contained change. Changes: * test/Microsoft.DotNet.ApiCompat.Tests/Microsoft.DotNet.ApiCompat.Tests.csproj: - Use Sdk="MSTest.Sdk", set UseMSTestSdk=true. - Drop ProjectReference to Microsoft.NET.TestFramework (unused). - Drop OutputType=Exe (MSTest.Sdk handles it). - Add Microsoft.VisualStudio.TestTools.UnitTesting global using. * test/Microsoft.DotNet.ApiCompat.Tests/RegexStringTransformerTests.cs: [Fact] -> [TestMethod], add [TestClass], Assert.Equal -> Assert.AreEqual. Verification: 5/5 tests pass on MTP in ~250 ms. Stacks on top of dotnet#54723 which stacks on dotnet#54722. Co-authored-by: Copilot <[email protected]>
b37a18b to
e964809
Compare
Same pattern as containerize.UnitTests (dotnet#54723). This project's single test file only uses xUnit Fact/Assert.Equal - no Microsoft.NET.TestFramework types - so the TestFramework ProjectReference can be dropped and the project switched to MSTest.Sdk in one self-contained change. Changes: * test/Microsoft.DotNet.ApiCompat.Tests/Microsoft.DotNet.ApiCompat.Tests.csproj: - Use Sdk="MSTest.Sdk", set UseMSTestSdk=true. - Drop ProjectReference to Microsoft.NET.TestFramework (unused). - Drop OutputType=Exe (MSTest.Sdk handles it). - Add Microsoft.VisualStudio.TestTools.UnitTesting global using. * test/Microsoft.DotNet.ApiCompat.Tests/RegexStringTransformerTests.cs: [Fact] -> [TestMethod], add [TestClass], Assert.Equal -> Assert.AreEqual. Verification: 5/5 tests pass on MTP in ~250 ms. Stacks on top of dotnet#54723 which stacks on dotnet#54722. Co-authored-by: Copilot <[email protected]>
… on MTP
Same pattern as previous migrations. None of the 6 test files used any
Microsoft.NET.TestFramework types - only xUnit primitives - so the
TestFramework ProjectReference can be dropped and the project switched to
MSTest.Sdk in one self-contained change.
Changes:
* test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/csproj:
- Use Sdk="MSTest.Sdk", set UseMSTestSdk=true.
- Drop ProjectReference to Microsoft.NET.TestFramework (unused).
- Drop OutputType=Exe (MSTest.Sdk handles it).
- Add Microsoft.VisualStudio.TestTools.UnitTesting global using.
* 6 test files: xUnit -> MSTest mechanical conversion plus targeted fixes:
- [Fact]/[Theory] -> [TestMethod], [InlineData] -> [DataRow], add [TestClass].
- Assert.True/False/Null/NotNull/Empty/NotEmpty/Equal/NotEqual ->
IsTrue/IsFalse/IsNull/IsNotNull/IsEmpty/IsNotEmpty/AreEqual/AreNotEqual.
- Assert.Single(x) -> Assert.HasCount(1, x).
- String Assert.Contains(needle, haystack) -> StringAssert.Contains(haystack, needle)
(xUnit and MSTest argument orders are reversed).
- One Assert.DoesNotContain(needle, str) -> Assert.IsFalse(str.Contains(needle)).
- Assert.Collection in BrowserScriptMiddlewareTest expanded to inline
Assert.HasCount + indexed AreEqual checks.
- Assert.ThrowsAsync<T> -> Assert.ThrowsExactlyAsync<T>.
- Assert.AreEqual on byte[]/int[] -> Assert.AreSequenceEqual (MSTEST0065:
MSTest does not do element-wise equality on collections; the analyzer
catches a real semantic difference vs xUnit).
- StringValues (Microsoft.Extensions.Primitives) ambiguity with
Assert.AreEqual<T> resolved by calling .ToString() at 5 call sites.
- xUnit v3 TestContext.Current.CancellationToken -> CancellationToken.None
(MSTest's TestContext.Current is experimental; tests do not actually
require test-cancellation propagation).
Verification: 110/110 tests pass on MTP in ~480 ms.
Stacks on dotnet#54724 which stacks on dotnet#54723 which stacks on dotnet#54722.
Co-authored-by: Copilot <[email protected]>
|
Re-validated this PR against the new Changes applied in the latest push on this branch: Other gotchas reviewed (no changes needed here):
Tests still pass locally on the bumped MSTest.Sdk. |
e964809 to
914956a
Compare
Same pattern as containerize.UnitTests (dotnet#54723). This project's single test file only uses xUnit Fact/Assert.Equal - no Microsoft.NET.TestFramework types - so the TestFramework ProjectReference can be dropped and the project switched to MSTest.Sdk in one self-contained change. Changes: * test/Microsoft.DotNet.ApiCompat.Tests/Microsoft.DotNet.ApiCompat.Tests.csproj: - Use Sdk="MSTest.Sdk", set UseMSTestSdk=true. - Drop ProjectReference to Microsoft.NET.TestFramework (unused). - Drop OutputType=Exe (MSTest.Sdk handles it). - Add Microsoft.VisualStudio.TestTools.UnitTesting global using. * test/Microsoft.DotNet.ApiCompat.Tests/RegexStringTransformerTests.cs: [Fact] -> [TestMethod], add [TestClass], Assert.Equal -> Assert.AreEqual. Verification: 5/5 tests pass on MTP in ~250 ms. Stacks on top of dotnet#54723 which stacks on dotnet#54722. Co-authored-by: Copilot <[email protected]>
… on MTP
Same pattern as previous migrations. None of the 6 test files used any
Microsoft.NET.TestFramework types - only xUnit primitives - so the
TestFramework ProjectReference can be dropped and the project switched to
MSTest.Sdk in one self-contained change.
Changes:
* test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/csproj:
- Use Sdk="MSTest.Sdk", set UseMSTestSdk=true.
- Drop ProjectReference to Microsoft.NET.TestFramework (unused).
- Drop OutputType=Exe (MSTest.Sdk handles it).
- Add Microsoft.VisualStudio.TestTools.UnitTesting global using.
* 6 test files: xUnit -> MSTest mechanical conversion plus targeted fixes:
- [Fact]/[Theory] -> [TestMethod], [InlineData] -> [DataRow], add [TestClass].
- Assert.True/False/Null/NotNull/Empty/NotEmpty/Equal/NotEqual ->
IsTrue/IsFalse/IsNull/IsNotNull/IsEmpty/IsNotEmpty/AreEqual/AreNotEqual.
- Assert.Single(x) -> Assert.HasCount(1, x).
- String Assert.Contains(needle, haystack) -> StringAssert.Contains(haystack, needle)
(xUnit and MSTest argument orders are reversed).
- One Assert.DoesNotContain(needle, str) -> Assert.IsFalse(str.Contains(needle)).
- Assert.Collection in BrowserScriptMiddlewareTest expanded to inline
Assert.HasCount + indexed AreEqual checks.
- Assert.ThrowsAsync<T> -> Assert.ThrowsExactlyAsync<T>.
- Assert.AreEqual on byte[]/int[] -> Assert.AreSequenceEqual (MSTEST0065:
MSTest does not do element-wise equality on collections; the analyzer
catches a real semantic difference vs xUnit).
- StringValues (Microsoft.Extensions.Primitives) ambiguity with
Assert.AreEqual<T> resolved by calling .ToString() at 5 call sites.
- xUnit v3 TestContext.Current.CancellationToken -> CancellationToken.None
(MSTest's TestContext.Current is experimental; tests do not actually
require test-cancellation propagation).
Verification: 110/110 tests pass on MTP in ~480 ms.
Stacks on dotnet#54724 which stacks on dotnet#54723 which stacks on dotnet#54722.
Co-authored-by: Copilot <[email protected]>
914956a to
865c83b
Compare
Same pattern as containerize.UnitTests (dotnet#54723). This project's single test file only uses xUnit Fact/Assert.Equal - no Microsoft.NET.TestFramework types - so the TestFramework ProjectReference can be dropped and the project switched to MSTest.Sdk in one self-contained change. Changes: * test/Microsoft.DotNet.ApiCompat.Tests/Microsoft.DotNet.ApiCompat.Tests.csproj: - Use Sdk="MSTest.Sdk", set UseMSTestSdk=true. - Drop ProjectReference to Microsoft.NET.TestFramework (unused). - Drop OutputType=Exe (MSTest.Sdk handles it). - Add Microsoft.VisualStudio.TestTools.UnitTesting global using. * test/Microsoft.DotNet.ApiCompat.Tests/RegexStringTransformerTests.cs: [Fact] -> [TestMethod], add [TestClass], Assert.Equal -> Assert.AreEqual. Verification: 5/5 tests pass on MTP in ~250 ms. Stacks on top of dotnet#54723 which stacks on dotnet#54722. Co-authored-by: Copilot <[email protected]>
… on MTP
Same pattern as previous migrations. None of the 6 test files used any
Microsoft.NET.TestFramework types - only xUnit primitives - so the
TestFramework ProjectReference can be dropped and the project switched to
MSTest.Sdk in one self-contained change.
Changes:
* test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/csproj:
- Use Sdk="MSTest.Sdk", set UseMSTestSdk=true.
- Drop ProjectReference to Microsoft.NET.TestFramework (unused).
- Drop OutputType=Exe (MSTest.Sdk handles it).
- Add Microsoft.VisualStudio.TestTools.UnitTesting global using.
* 6 test files: xUnit -> MSTest mechanical conversion plus targeted fixes:
- [Fact]/[Theory] -> [TestMethod], [InlineData] -> [DataRow], add [TestClass].
- Assert.True/False/Null/NotNull/Empty/NotEmpty/Equal/NotEqual ->
IsTrue/IsFalse/IsNull/IsNotNull/IsEmpty/IsNotEmpty/AreEqual/AreNotEqual.
- Assert.Single(x) -> Assert.HasCount(1, x).
- String Assert.Contains(needle, haystack) -> StringAssert.Contains(haystack, needle)
(xUnit and MSTest argument orders are reversed).
- One Assert.DoesNotContain(needle, str) -> Assert.IsFalse(str.Contains(needle)).
- Assert.Collection in BrowserScriptMiddlewareTest expanded to inline
Assert.HasCount + indexed AreEqual checks.
- Assert.ThrowsAsync<T> -> Assert.ThrowsExactlyAsync<T>.
- Assert.AreEqual on byte[]/int[] -> Assert.AreSequenceEqual (MSTEST0065:
MSTest does not do element-wise equality on collections; the analyzer
catches a real semantic difference vs xUnit).
- StringValues (Microsoft.Extensions.Primitives) ambiguity with
Assert.AreEqual<T> resolved by calling .ToString() at 5 call sites.
- xUnit v3 TestContext.Current.CancellationToken -> CancellationToken.None
(MSTest's TestContext.Current is experimental; tests do not actually
require test-cancellation propagation).
Verification: 110/110 tests pass on MTP in ~480 ms.
Stacks on dotnet#54724 which stacks on dotnet#54723 which stacks on dotnet#54722.
Co-authored-by: Copilot <[email protected]>
Imports the migrate-xunit-to-mstest skill from dotnet/skills@main (plugins/dotnet-test/skills/migrate-xunit-to-mstest) into this repo so the xUnit -> MSTest migration that's currently in progress (#54722, #54723, #54724, #54725, #54726) has a documented, repeatable procedure that contributors and agents can follow consistently. Files added (verbatim from upstream): - .github/skills/migrate-xunit-to-mstest/SKILL.md - .github/skills/migrate-xunit-to-mstest/references/mapping-cheatsheet.md Note: SKILL.md is 546 lines, slightly above the 500-line "Progressive Disclosure" guideline checked by .github/skills/ValidateSkill.cs. The validator is advisory (not CI-enforced) and we are intentionally mirroring the upstream content verbatim to keep future syncs trivial. Co-authored-by: Copilot <[email protected]>
|
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 |
|
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). |
AspireLauncherIntegrationTests exec the Aspire launcher (Microsoft.DotNet.HotReload.Watch.Aspire) as a child process. ExcludeAssets=Runtime omitted the launcher's transitive runtime dependencies (Microsoft.CodeAnalysis*) from the test output, so the launched process crashed at startup with FileNotFoundException and the tests failed with Assert.NotNull. Removing ExcludeAssets=Runtime deploys the full closure next to the launcher. Co-authored-by: Copilot <[email protected]>
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: Copilot <[email protected]>
…tionTests) PR dotnet#54766 enabled the Recommended MSTest analyzers as errors; dotnet#54758 merged shortly after with violations that are now build errors, leaving main red and blocking all open migration PRs. Fix the two affected files: - CommandResultAssertions.MSTest.cs: MSTEST0037 (IsTrue(a==b)->AreEqual, IsFalse(a==b) ->AreNotEqual) and MSTEST0023 (IsTrue(!x)->IsFalse(x)). - LocalizeTemplateTests.cs: MSTEST0037 (AreEqual(n, x.Length)->HasCount(n, x)). Co-authored-by: Copilot <[email protected]> (cherry picked from commit 6ac4ef0)
Co-authored-by: Copilot <[email protected]> (cherry picked from commit 1db59ec)
The project already uses Sdk="MSTest.Sdk", which sets $(UsingMSTestSdk) automatically. test/Directory.Build.targets gates the xUnit-specific defaults on $(UsingMSTestSdk), so the custom $(UseMSTestSdk) property had no effect. Co-authored-by: Copilot <[email protected]>
|
/ba-g #54819 |
|
/ba-g #54819 |
# Conflicts: # test/Microsoft.DotNet.HotReload.Watch.Aspire.Tests/Microsoft.DotNet.HotReload.Watch.Aspire.Tests.csproj
|
Closing as a related stacked PR got merged earlier. |
Pull request was closed
Follow-up to the pathfinder PR #54722 (which this stacks on).
containerize.UnitTestsonly uses xUnitFact/Theory/InlineData/AssertAPIs — it does not use any types fromMicrosoft.NET.TestFramework. So the project can drop its TestFrameworkProjectReferenceand switch toMSTest.Sdkin one self-contained change.Changes
test/containerize.UnitTests/containerize.UnitTests.csprojSdk="MSTest.Sdk", setUseMSTestSdk=true(opts the project out of the xUnit defaults intest/Directory.Build.targets— gate introduced in Migrate Microsoft.DotNet.HotReload.Watch.Aspire.Tests to MSTest.Sdk on MTP (pathfinder) #54722).ProjectReferencetoMicrosoft.NET.TestFramework(unused).OutputType=Exe(MSTest.Sdk handles it).Microsoft.VisualStudio.TestTools.UnitTestingglobal using.test/containerize.UnitTests/ParserTests.cs: xUnit → MSTest mechanical conversion:[Fact]/[Theory]→[TestMethod],[InlineData]→[DataRow], add[TestClass],Assert.NotNull/Equal/Empty/Single→IsNotNull/AreEqual/IsEmpty/HasCount(1, ...).Verification
✅ 9/9 tests pass on MTP (~400 ms).
Merge ordering
Depends on #54722. Once that merges, this PR will rebase cleanly onto
main.Relates to #52914.