dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

Use 'dotnet test' to run .NET unit tests on Android #26930

Open melanchall opened 2 years ago

melanchall commented 2 years ago

I'm developing a library. And I have a test project (jn NUnit) within the library solution. I successfully run my unit tests on desktop platforms (Windows, macOS, Ubuntu) via dotnet test on MS-hosted agents within Azure Pipelines.

.NET 6 states it supports mobile platforms. So I want to run my unit tests on them. First of all, on Android. But I absolutely don't understand where to start from, how setup environment during CI on Azure Pipelines and so on.

Is it possible? Maybe there are some guides or official articles how it can be done.

evgenyvalavin commented 1 year ago

+1 Seems like NUnit needs a test adapter for Android

nohwnd commented 1 year ago

I am not an expert on Android, but the execution is probably running via Mono, you would need a way to deploy to the remote device (UWP for example does that via Visual Studio deployer services), and it extends vstest (https://github.com/microsoft/vstest) which powers dotnet test by using ITestRuntimeProvider extension point. This extension point deploys and then starts the testhost (the executable that runs tests on the remote side).

I assume for your need you would need s testhost that can run on android, maybe the testhost we ship with vstest could run there as well, but more likely you need a specialize less capable testhost that is okay running in the restricted environment of android device.

And from there you just send back messages over you chosen transport. Test platform now supports just Json over TCP, but you could stand-up a proxy in the middle that forwards your messages however you like.