[dotnet] Fix dotnet test on macOS and Mac Catalyst templates#25963
[dotnet] Fix dotnet test on macOS and Mac Catalyst templates#25963jonathanpeppers wants to merge 1 commit into
dotnet test on macOS and Mac Catalyst templates#25963Conversation
2f097c9 to
b6903ad
Compare
There was a problem hiding this comment.
Pull request overview
Fixes dotnet test execution for macOS and Mac Catalyst test templates by ensuring Microsoft.Testing.Platform (MTP) handshake arguments and launch behavior are compatible with desktop app launching semantics.
Changes:
- Forward MTP protocol command-line arguments from the running process into
TestApplication.CreateBuilderAsyncin all test templates. - Default MSTest desktop launches to execute the app binary directly (disable
open/LaunchServices path) to preserve CLI args and environment for MTP. - Re-enable macOS/Mac Catalyst coverage in
DotNetTestTestand avoid simulator boot/shutdown for desktop platforms.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/dotnet/UnitTests/DotNetTestTest.cs | Re-enables macOS/Mac Catalyst template coverage and skips simulator management for desktop runs. |
| dotnet/Templates/Microsoft.tvOS.Templates/tvostest/csharp/Main.cs | Forwards MTP args into the test app builder. |
| dotnet/Templates/Microsoft.macOS.Templates/macostest/csharp/Main.cs | Forwards MTP args into the test app builder (macOS). |
| dotnet/Templates/Microsoft.MacCatalyst.Templates/maccatalysttest/csharp/Main.cs | Forwards MTP args into the test app builder (Mac Catalyst). |
| dotnet/Templates/Microsoft.iOS.Templates/iostest/csharp/Main.cs | Forwards MTP args into the test app builder. |
| dotnet/targets/Xamarin.Shared.Sdk.MSTest.props | Sets RunWithOpen default to false for MSTest projects to avoid LaunchServices argument/env propagation issues. |
cd320db to
46b0078
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // Forward args from 'dotnet test', which sends the MTP protocol config | ||
| // (--server / --dotnet-test-pipe) via the command line. | ||
| string [] cliArgs = Environment.GetCommandLineArgs (); | ||
| string [] mtpArgs = cliArgs.Length > 1 ? cliArgs [1..] : []; |
There was a problem hiding this comment.
This seems to drop the first argument, but I can't see any explanation/comment of why this is necessary?
There was a problem hiding this comment.
Added a comment noting that Environment.GetCommandLineArgs()[0] is the executable path, not an argument.
`dotnet test` on the `macostest` and `maccatalysttest` templates was failing with "Zero tests ran" and Microsoft.Testing.Platform (MTP) handshake failures. Two bugs, both needed for the desktop platforms to work: 1. The desktop test templates' `Main.cs` was dropping the incoming `args` when calling `TestApplication.CreateBuilderAsync`. `dotnet test` invokes the app with MTP protocol arguments appended to the command line (the server type and the named-pipe path for the test host), so discarding `args` disables the MTP handshake. Forward the current process' command-line arguments into `CreateBuilderAsync` alongside the existing `--results-directory` / `--report-trx` args. iOS and tvOS aren't affected because mlaunch forwards MTP env vars into the simulator and MTP picks up the protocol config from those env vars. 2. On macOS and Mac Catalyst the default `dotnet run/test` launch path goes through `open` (LaunchServices), which does not propagate the parent process' environment variables and does not reliably forward trailing CLI arguments to the app. Default `RunWithOpen` to `false` in `Xamarin.Shared.Sdk.MSTest.props` so MSTest projects launch the app binary directly. This is a no-op for iOS/tvOS (`RunWithOpen` is only consulted by the desktop targets). Re-enable the previously-commented-out `[TestCase]` entries for `maccatalysttest` and `macostest` in `DotNetTestTest`, and skip the simulator boot/shutdown steps for desktop platforms. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
46b0078 to
4da16b4
Compare
✅ [CI Build #7e67820] Prepare .NET Release succeeded ✅📦 Published NuGet packages (32 packages)iOS
MacCatalyst
macOS
tvOS
Other
Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #4da16b4] Build passed (Build packages) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #4da16b4] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 3 tests failed, 253 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (tvOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)1 tests failed, 22 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
✅ [CI Build #4da16b4] Build passed (Build macOS tests) ✅Pipeline on Agent |
🔥 [PR Build #4da16b4] Build failed (Detect API changes) 🔥Build failed for the job 'Detect API changes' (with job status 'Failed') Pipeline on Agent |
|
🔥 Unable to find the contents for the comment: D:\a\1\s\change-detection\results\gh-comment.md does not exist :fire Pipeline on Agent |
dotnet teston themacostestandmaccatalysttesttemplates was failing with "Zero tests ran" and Microsoft.Testing.Platform (MTP) handshake failures.Two bugs, both needed for the desktop platforms to work:
The desktop test templates'
Main.cswas dropping the incomingargswhen callingTestApplication.CreateBuilderAsync.dotnet testinvokes the app with MTP protocol arguments appended to the command line (the server type and the named-pipe path for the test host), so discardingargsdisables the MTP handshake. Forward the current process' command-line arguments intoCreateBuilderAsyncalongside the existing--results-directory/--report-trxargs. iOS and tvOS aren't affected becausemlaunchforwards MTP env vars into the simulator and MTP picks up the protocol config from those env vars.On macOS and Mac Catalyst the default
dotnet run/testlaunch path goes throughopen(LaunchServices), which does not propagate the parent process' environment variables and does not reliably forward trailing CLI arguments to the app. DefaultRunWithOpentofalseinXamarin.Shared.Sdk.MSTest.propsso MSTest projects launch the app binary directly. This is a no-op for iOS/tvOS (RunWithOpenis only consulted by the desktop targets).Re-enable the previously-commented-out
[TestCase]entries formaccatalysttestandmacostestinDotNetTestTest, and skip the simulator boot/shutdown steps for desktop platforms.Verified locally
dotnet new macostest/dotnet new maccatalysttest+dotnet test, using the default template's built-in tests (1 passing, 1 skipped, 1 expected-to-fail):No handshake failures, per-test results reported via MTP protocol, exit code matches the expected failure.