Xamarin UI 测试确定平台

Xamarin UI Test Determine Platform

我正在尝试使用 Xamarin UI Test 编写自动化测试,在这些测试的某些部分中,我需要知道它们 运行 在哪个平台上,即 Android 或 iOS.

我正在努力寻找一种方法来做到这一点,有人知道 API 可以做到这一点或任何其他类似的技巧吗?

你的测试class有一个像这样的构造函数:

[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests
{
    IApp app;
    Platform platform;

    public Tests(Platform platform)
    {
        this.platform = platform;
    }

    [SetUp]
    public void BeforeEachTest()
    {
        app = AppInitializer.StartApp(platform);
    }
}

稍后,在您的测试方法中,您可以这样做:

[Test]
public void MyTest()
{
    if (platform == Platform.Android) 
    {
        // Do specific code here.
    }
}