Skip to content

[Microsoft.Android.Run] Support MTP server-mode discovery - #13409

Draft
simonrozsival wants to merge 5 commits into
mainfrom
simonrozsival-mtp-server-mode
Draft

simonrozsival wants to merge 5 commits into
mainfrom
simonrozsival-mtp-server-mode

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Context: #13531, #13434

The Android test launcher supports dotnet test discovery and execution, but IDEs using the public Microsoft.Testing.Platform JSON-RPC server protocol also need discovery metadata and selected-test execution. Add server mode and forward selected test UIDs to the androidtest instrumentation using the embedded MTP client already present on main.

Preserve the existing discovery event and compatibility with older APKs for unfiltered discovery. Selected execution requires an updated APK; the launcher probes for selection support before executing. Larger selections are transferred through an app-specific file. The template uses MSTest source generation in ReflectionFree mode to preserve test metadata under trimming, and each test class must have [TestClass] directly rather than inheriting it. Build, installation, and device selection remain client responsibilities.

Validation:

  • dotnet test tests/Microsoft.Android.Run-Tests/Microsoft.Android.Run-Tests.csproj -v minimal — passed, 24 tests.
  • dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -v minimal -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0 --filter 'FullyQualifiedName~StreamingTests' — passed, 16 tests.
  • make prepare CONFIGURATION=Debug MSBUILD_ARGS='-m:4' && make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:4' — passed.
  • ./dotnet-local.sh build tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj -v minimal -p:EnableSourceControlManagerQueries=false -p:EnableSourceLink=false — passed.
  • EnableSourceControlManagerQueries=false EnableSourceLink=false ADB_TARGET='-s emulator-5556' ./dotnet-local.sh test bin/TestDebug/MSBuildDeviceIntegration/net11.0/MSBuildDeviceIntegration.dll --filter 'Name~DotNetNewAndroidTest&Name~generic' -v minimal — passed, 2 tests. A wider device run initially passed 12 of 14 cases; its two generic cases failed on an incorrect expected discovery count and passed after correcting the assertion.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 14:23
@simonrozsival
simonrozsival marked this pull request as draft November 5, 2026 14:24

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.

🟡 Changes recommended

Unresolved defects can break discovery for generic-parameter tests or normal adb startup, prevent large test selections from launching on Windows, and fail host tests when work-directory paths contain spaces.

4 open issues
What changed in this PR

Adds public Microsoft.Testing.Platform (MTP) server-mode discovery and selected-test execution to the Android launcher, enabling compatible IDE clients while preserving the existing dotnet test transport and opaque test UIDs.

Changes:

  • Adds JSON-RPC server options, discovery requests, UID filtering, and method metadata.
  • Updates NUnit instrumentation and the MSTest template for discovery without execution, including Release trimming support.
  • Adds host protocol regressions, device-template coverage, and usage documentation.
File Description
tests/​TestRunner.Core/​TestInstrumentation.cs Adds NUnit discovery, UID filtering, and method metadata.
tests/​MSBuildDeviceIntegration/​Tests/​InstallAndRunTests.cs Covers template discovery and selected execution, including Release discovery.
tests/​Microsoft.Android.Run-Tests/​Microsoft.Android.Run-Tests.csproj Defines the new host protocol test project.
tests/​Microsoft.Android.Run-Tests/​FakeAdb.cs Supplies simulated adb responses for host tests.
tests/​Microsoft.Android.Run-Tests/​AndroidTestAdapterTests.cs Tests discovery, filtering, failures, and JSON-RPC sessions.
src/​Microsoft.Android.Templates/​androidtest/​TestInstrumentation.cs Adds MSTest discovery and richer streamed results.
src/​Microsoft.Android.Templates/​androidtest/​AndroidTest1.csproj Adds the embedded server client and roots the test assembly.
src/​Microsoft.Android.Run/​Program.cs Accepts public server-mode and console discovery arguments.
src/​Microsoft.Android.Run/​Microsoft.Android.Run.csproj Exposes internals to the host tests.
src/​Microsoft.Android.Run/​InstrumentationProtocol.cs Defines discovery metadata and encoded UID transport.
src/​Microsoft.Android.Run/​AndroidTestAdapter.cs Handles discovery, selected execution, and metadata publication.
NuGet.config Adds the test-tools package feed.
Microsoft.Android.slnx Includes the host protocol test project.
Documentation/​workflow/​UnitTests.md Documents discovery support and deployment prerequisites.
.github/​skills/​tests/​references/​test-catalog.md Lists the standalone host test command.

Review effort: Balanced

simonrozsival and others added 4 commits November 21, 2026 09:31
Enable IDE clients to discover and execute on-device tests through the public MTP JSON-RPC server protocol.  Preserve the existing dotnet test transport and forward selected test UIDs without changing their identity.

Add discovery and method metadata to the NUnit instrumentation and MSTest template, preserve test assemblies under trimming, and cover the host protocol and generated applications with regression tests.

Co-authored-by: Copilot App <[email protected]>
Use matching MSTest and MSTest.SourceGeneration 4.4.1 packages in ReflectionFree mode instead of rooting the complete test assembly. Verify trimmed discovery and execution, individual data-row selection, and removal of unrelated code.

Co-authored-by: Copilot App <[email protected]>
Transfer large test selections through a device file, tolerate benign adb discovery output, and match MSTest managed parameter names. Add host and device regressions, including fake adb paths with spaces.

Co-authored-by: Copilot App <[email protected]>
Ignore adb informational stderr after successful discovery and align the streaming test fixture with the current discovery event contract.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival force-pushed the simonrozsival-mtp-server-mode branch from 3ce7ccf to d9790ef Compare November 21, 2026 13:15
Reuse the embedded MTP client and discovery protocol now present on main, while retaining public server mode, selected-test execution, and discovery metadata. Remove the obsolete NUnit instrumentation and NuGet feed changes.

Co-authored-by: Copilot App <[email protected]>

This branch has not been deployed

No deployments
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.

3 participants