镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[androidtest] Support dotnet test --list-tests - #13531

Draft
jonathanpeppers wants to merge 5 commits into
mainfrom
jonathanpeppers-androidtest-list-tests
Draft

jonathanpeppers wants to merge 5 commits into
mainfrom
jonathanpeppers-androidtest-list-tests

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

In a dotnet new androidtest project, dotnet test --list-tests reports 0 tests and exits with code 8. There are two causes:

  1. AndroidTestAdapter in Microsoft.Android.Run handles only RunTestExecutionRequest and ignores DiscoverTestExecutionRequest.
  2. On the device, Microsoft.Testing.Platform (MTP) does not send discovery results to user IDataConsumers. TestHostBuilder skips building them when IsForDiscoveryRequest is true. This is still true in MTP 3.0 previews.

Changes:

  • Host: AndroidTestAdapter handles DiscoverTestExecutionRequest. It runs am instrument -e list-tests true, then publishes each event=discovered status as a discovered test node.
  • Template: TestInstrumentation.cs hosts MSTest in-process with MtpServerClient.LaunchInProcessAsync. The client comes from the source-only package Microsoft.Testing.Platform.ServerMode.Client.Sources, whose docs name embedded Android/iOS test runners as a use. The template calls DiscoverTestsAsync or RunTestsAsync and streams discovered/start/finish statuses with the existing instrumentation protocol. Discovery and runs use the same test UIDs.
  • SDK: GenerateDocumentationFile now defaults to false when EnableMSTestRunner=true. Without this, a broken XML doc cref in the client package source gives warning CS1574 in every test app.

Existing projects keep working: their instrumentation does not send event statuses, so the host still uses the TRX fallback. To get --list-tests, they must update TestInstrumentation.cs and add the package reference.

Tests:

  • New StreamingTests cases: discovery with --list-tests, and the TRX fallback that the previous template uses.
  • New DotNetNewAndroidTest case: list.

Tested:

  • On a Pixel 5, with the installed .NET 11 SDK and a locally built Microsoft.Android.Run.dll, on a new androidtest project:
    • dotnet test --list-tests in Debug and Release: 3 tests discovered.
    • dotnet test --report-trx: 1 passed, 1 failed (with message and stack trace), 1 skipped, and a TRX file.
    • dotnet run: the same counts in INSTRUMENTATION_RESULT.
  • StreamingTests on Windows: 6/6 passed. These tests use a Unix shell fake adb and are skipped on Windows, so I ran them with a temporary .cmd fake adb, which is not committed.
  • Not run locally: the full SDK build and DotNetNewAndroidTest. These depend on CI. The GenerateDocumentationFile change also depends on CI, because my device tests used the installed SDK.

jonathanpeppers and others added 5 commits November 12, 2026 13:49
The host adapter (Microsoft.Android.Run) ignored DiscoverTestExecutionRequest,
so --list-tests reported 0 tests (exit code 8). It now runs
'am instrument -e list-tests true' and publishes discovered tests.

On device, MTP does not send discovery results to user IDataConsumers, so the
androidtest template now hosts MSTest in-process with MtpServerClient
(Microsoft.Testing.Platform.ServerMode.Client.Sources) and streams discovered
tests and results back with the instrumentation streaming protocol.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move this from the androidtest template into the SDK defaults, so test
apps do not get CS1574 from the MTP server-mode client source package.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove the discovered-count result and its check, merge the test state
mapping into one switch, and read the TRX path directly from the run
result artifacts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

1 participant