Skip to content

[dotnet test] Add androidtest project template and dotnet run instrumentation support#10862

Draft
jonathanpeppers wants to merge 1 commit intomainfrom
dev/peppers/androidtest
Draft

[dotnet test] Add androidtest project template and dotnet run instrumentation support#10862
jonathanpeppers wants to merge 1 commit intomainfrom
dev/peppers/androidtest

Conversation

@jonathanpeppers
Copy link
Member

Context: #10683

Add a new androidtest .NET project template that creates an Android test project using MSTest with Microsoft.Testing.Platform. The template includes a TestInstrumentation class that runs tests via am instrument and reports results (passed/failed/skipped) back through Android's instrumentation protocol.

Add --instrument option to Microsoft.Android.Run so dotnet run can launch test projects via am instrument -w instead of am start.

Fix an issue where NuGet packages like MSTest add assemblies as both properly-resolved publish assets (with DestinationSubPath metadata) and as None items (without DestinationSubPath) that flow into _SourceItemsToCopyToPublishDirectory. When NuGet conflict resolution arbitrarily picks the None-based copy, the assembly loses its DestinationSubPath and TargetPath metadata, causing it to either be missing from the APK or deployed to the wrong directory on device. The fix conditionally removes only items without DestinationSubPath, then re-adds any assemblies that were completely stripped with a cleared TargetPath so that downstream targets (ProcessAssemblies, FastDeploy) can set the correct per-architecture paths.

Changes:

  • New androidtest template under src/Microsoft.Android.Templates/
  • New GetAndroidInstrumentationName MSBuild task to resolve the instrumentation runner class from AndroidManifest.xml
  • Updated Microsoft.Android.Sdk.Application.targets to pass --instrument when EnableMSTestRunner is true
  • Added AdbHelper class to Microsoft.Android.Run for shared adb process management
  • Added --instrument CLI option to Microsoft.Android.Run/Program.cs
  • Fixed _ComputeFilesToPublishForRuntimeIdentifiers to preserve properly-resolved publish assets and recover missing assemblies
  • Added DotNetNewAndroidTest device integration test

TODO:

  • In a future PR, add support for dotnet test end-to-end.

…trumentation support

Context: #10683

Add a new `androidtest` .NET project template that creates an Android
test project using MSTest with Microsoft.Testing.Platform. The template
includes a TestInstrumentation class that runs tests via `am instrument`
and reports results (passed/failed/skipped) back through Android's
instrumentation protocol.

Add `--instrument` option to Microsoft.Android.Run so `dotnet run`
can launch test projects via `am instrument -w` instead of `am start`.

Fix an issue where NuGet packages like MSTest add assemblies as both
properly-resolved publish assets (with DestinationSubPath metadata) and
as None items (without DestinationSubPath) that flow into
`_SourceItemsToCopyToPublishDirectory`. When NuGet conflict resolution
arbitrarily picks the None-based copy, the assembly loses its
DestinationSubPath and TargetPath metadata, causing it to either be
missing from the APK or deployed to the wrong directory on device.
The fix conditionally removes only items without DestinationSubPath,
then re-adds any assemblies that were completely stripped with a cleared
TargetPath so that downstream targets (ProcessAssemblies, FastDeploy)
can set the correct per-architecture paths.

Changes:

- New `androidtest` template under src/Microsoft.Android.Templates/
- New GetAndroidInstrumentationName MSBuild task to resolve the
  instrumentation runner class from AndroidManifest.xml
- Updated Microsoft.Android.Sdk.Application.targets to pass
  `--instrument` when EnableMSTestRunner is true
- Added AdbHelper class to Microsoft.Android.Run for shared adb
  process management
- Added `--instrument` CLI option to Microsoft.Android.Run/Program.cs
- Fixed _ComputeFilesToPublishForRuntimeIdentifiers to preserve
  properly-resolved publish assets and recover missing assemblies
- Added DotNetNewAndroidTest device integration test

TODO:
- In a future PR, add support for `dotnet test` end-to-end.
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