-
Notifications
You must be signed in to change notification settings - Fork 1.8k
DeviceTests
The tests on these projects are written using XUnit. They are deployed to a device and can be run either visually our with a headless testrunner. The Device tests projects are built for all platforms, so when you write a test it will appear for all different frameworks net7.0-android net7.0-ios net7.0-windows net7.0-maccatalyst . You can include or exclude a test from a particular platform by wrapping your test method on a compile directive e.g. #if !WINDOWS. On device tests what we want to test normally is if we changed something on the cross platform layer the native representation has the value we expect.
[Theory("Text transform updates correctly)]
[ClassData(typeof(TextTransformCases))]
public async Task TextTransformUpdated(string text, TextTransform transform, string expected)
{
//Create my cross platform Button
var control = new Button() { Text = text };
//Create it's handler so i can grab the native view and Assert
var handler = await CreateHandlerAsync<ButtonHandler>(control);
//Change a value on my cross platform layer
await InvokeOnMainThreadAsync(() => control.TextTransform = transform);
//Helper method to grab the text from the native button (UIButton, MaterialButton)
var platformText = await GetPlatformText(handler);
//Assert that the value is what we expect
Assert.Equal(expected, platformText);
}
To run the tests on iOS or Catalyst, you'll need a Mac. To run the tests on Windows, you'll need a Windows machine. Android tests can be run from either platform.
Make sure a dotnet tool restore on the repo home Make sure DeveloperMode is turned on Make sure you have maui workloads installed
Make sure a dotnet tool restore on the repo home Make sure you have maui workloads installed
Ensure that you have the Android API 30 SDK installed, with the emulator image for Play store on x86/x64. By default, the tests use that. See screenshot below. If you want to use another image you can specify the --device
argument, with something like --device="android-emulator-64_33"
where the 64 means image x86_x64 and 33 indicates the API level.
- Build the project and open VS
dotnet cake --target=vs --workloads=global
- Deploy project to iOS or Android device or simulator.
./build.ps1 --target=dotnet-buildtasks --configuration="Release" --workloads=global
iOS
dotnet cake -script eng/devices/ios.cake --project="/Users/ruimarinho/dotnet/maui/src/Graphics/tests/DeviceTests/Graphics.DeviceTests.csproj" --device=ios-simulator-64 --workloads=global
dotnet cake -script eng/devices/ios.cake --project="/Users/ruimarinho/dotnet/maui/src/Core/tests/DeviceTests/Core.DeviceTests.csproj" --device=ios-simulator-64 --workloads=global
dotnet cake -script eng/devices/ios.cake --project="/Users/ruimarinho/dotnet/maui/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj" --device=ios-simulator-64 --workloads=global
dotnet cake -script eng/devices/ios.cake --project="/Users/ruimarinho/dotnet/maui/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj" --device=ios-simulator-64 --workloads=global
dotnet cake -script eng/devices/ios.cake --project="/Users/ruimarinho/dotnet/maui/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj" --device=ios-simulator-64 --workloads=global
Windows
dotnet cake -script eng/devices/windows.cake --project="C:\repos\dotnet\maui\src\Core\tests\DeviceTests\Core.DeviceTests.csproj" --device="unpackaged" --packageid=com.microsoft.maui.core.devicetests --workloads=global
dotnet cake -script eng/devices/windows.cake --project="C:\repos\dotnet\maui\src\Controls\tests\DeviceTests\Controls.DeviceTests.csproj" --device="unpackaged" --packageid=com.microsoft.maui.controls.devicetests --workloads=global
dotnet cake -script eng/devices/windows.cake --project="C:/repos/dotnet/maui/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj" --device="unpackaged" --packageid=Microsoft.Maui.MauiBlazorWebView.DeviceTests --workloads=global