4

I have a Xamarin.UITest project than contains UI tests for both Android and iOS. All tests inherit from a base class that looks like:

[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public abstract class UITestBase
{
    private readonly Platform _platform;
    protected IApp App { get; private set; }

    protected UITestBase(Platform platform)
    {
        _platform = platform;
    }

    [SetUp]
    protected virtual async Task BeforeEachTest()
    {
        App = AppInitializer.StartApp(_platform);
        await Task.CompletedTask;
    }
}

So, all tests will run for both Android and iOS. Now, in an IDE such as Visual Studio or Rider, it easily lets me run tests only for a specific platform - while developing, I often only want to run tests for Android, for example.

How can I run tests only for a specific platform from the command line?

dotnet test will run them for both platforms, and I can't see a way to filter using NUnit's TestFixture attribute.

While I'd prefer a method using dotnet test, it would also be OK to use the NUnit console runner, nunit3-console.exe, but again I can't figure out how to filter using TestFixture arguments.

Cocowalla
  • 13,822
  • 6
  • 66
  • 112
  • You can try the answer in [this thread](https://stackoverflow.com/questions/52699329/how-to-specify-the-platform-android-or-ios-test-with-nunit-console). – nevermore Oct 31 '19 at 03:06
  • 1
    @JackHua-MSFT that does at least work for individual tests, but I can't find a way to make it run all tests (tried wildcards): `nunit3-console.exe MyAssembly.dll --test="My.Fully.Qualified.Test.Class(Android)"` – Cocowalla Oct 31 '19 at 09:36
  • Category parameter worked perfectly but I couldn't make text fixture parameter work. nunit3-console.exe Xamarin.UITest.dll --where=cat==High – sermet Nov 12 '19 at 06:24
  • Does `dotnet test` really work? It only restores my ui test project but doesn't run any tests – pschlz Dec 02 '20 at 16:44
  • @pschlz yes, or at least "it works on my machine" :P – Cocowalla Dec 02 '20 at 20:30
  • @Cocowalla It's now working on my machine. The trick was not to use Xamarin.UITest Cross-Platform template but to create a NUnut Test Project (.NET Core), copy the relevant files from UI Test project and set the TargetFramework in .csproj file to `net472` – pschlz Dec 08 '20 at 12:39

1 Answers1

1

With dotnet-test (see run selective unit tests)

dotnet test Tests.dll--filter iOS

dotnet test Tests.dll--filter Android

Or use nunit3-console-runner with Test Selection Language :

nunit3-console.exe Tests.dll --where "test =~ iOS"

nunit3-console.exe Tests.dll --where "test =~ Android"
pschlz
  • 173
  • 1
  • 12