test(postit.android): add Xamarin.UITest smoke test on emulator
Adds AndroidAppLaunchTests to PostIt.Tests, a Xamarin.UITest-based smoke test that launches the installed com.CompanyName.PostIt app on the running emulator and waits for the first Avalonia frame to render. The test skips cleanly when the app is not installed. Currently FAILS RED on the local emulator: the installed APK has no Activity declared (am start returns result code=-92, ACTIVITY_NOT_FOUND), and Xamarin.UITest's test server cannot reach /ping. This is a guardian test that will turn green once EmbedAssembliesIntoApk=true is set in PostIt.Android.csproj (follow-up commit). Also adds a Debug launch config in .vscode/launch.json that runs the test under vsdbg, enabling breakpoints and object inspection when investigating the failure.
This commit is contained in:
parent
1167169aa8
commit
41cc651b7d
4 changed files with 91 additions and 1 deletions
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
|
|
@ -28,6 +28,19 @@
|
|||
"request": "launch",
|
||||
"projectPath": "${workspaceFolder}/src/PostIt/PostIt.Desktop/PostIt.Desktop.csproj",
|
||||
|
||||
},
|
||||
{
|
||||
"name": "Test PostIt.Android launch (Xamarin.UITest)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/src/PostIt.Tests/bin/Debug/net10.0/PostIt.Tests.dll",
|
||||
"args": [
|
||||
"--filter-method",
|
||||
"PostIt.Tests.AndroidAppLaunchTests.PostIt_starts_and_draws_a_first_frame_on_the_emulator"
|
||||
],
|
||||
"cwd": "${workspaceFolder}/src/PostIt.Tests",
|
||||
"console": "integratedTerminal",
|
||||
"stopAtEntry": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
76
src/PostIt.Tests/AndroidAppLaunchTests.cs
Normal file
76
src/PostIt.Tests/AndroidAppLaunchTests.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xamarin.UITest;
|
||||
using Xamarin.UITest.Android;
|
||||
using Xunit;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Smoke test: launches the installed PostIt.Android app on the running
|
||||
/// emulator and waits for the first Avalonia frame to render. Reveals the
|
||||
/// "démarrage KO" bug — the test fails if Avalonia never draws a frame
|
||||
/// within the timeout.
|
||||
///
|
||||
/// Skip conditions: the package is not installed on the connected device,
|
||||
/// or no device is connected via adb.
|
||||
/// </summary>
|
||||
public class AndroidAppLaunchTests
|
||||
{
|
||||
private const string PackageName = "com.CompanyName.PostIt";
|
||||
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public AndroidAppLaunchTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostIt_starts_and_draws_a_first_frame_on_the_emulator()
|
||||
{
|
||||
if (!IsPackageInstalledOnAnyDevice())
|
||||
{
|
||||
_output.WriteLine($"[skip] {PackageName} not installed on any device");
|
||||
return;
|
||||
}
|
||||
|
||||
_output.WriteLine($"[step] configuring app via InstalledApp({PackageName})");
|
||||
var app = ConfigureApp.Android
|
||||
.InstalledApp(PackageName)
|
||||
.StartApp(Xamarin.UITest.Configuration.AppDataMode.DoNotClear);
|
||||
_output.WriteLine("[step] app.StartApp returned, waiting for first frame");
|
||||
|
||||
app.WaitForElement(
|
||||
e => e.Class("android.view.View"),
|
||||
timeout: TimeSpan.FromSeconds(30));
|
||||
_output.WriteLine("[step] first frame observed");
|
||||
}
|
||||
|
||||
private static bool IsPackageInstalledOnAnyDevice()
|
||||
{
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo("adb", "shell pm list packages")
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
using var proc = Process.Start(startInfo);
|
||||
if (proc is null) return false;
|
||||
var stdout = proc.StandardOutput.ReadToEnd();
|
||||
proc.WaitForExit(5000);
|
||||
return stdout
|
||||
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
|
||||
.Any(line => line.Trim().Equals($"package:{PackageName}", StringComparison.Ordinal));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<Project>
|
||||
<!-- Pull in shared package versions from the repository root. -->
|
||||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Packages.props', '$(MSBuildThisFileDirectory)../'))" />
|
||||
|
||||
<!-- PostIt.Tests-specific versions -->
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Avalonia.Headless" Version="12.0.4" />
|
||||
<PackageVersion Include="Avalonia.Headless.XUnit" Version="12.0.4" />
|
||||
<PackageVersion Include="Xamarin.UITest" Version="4.4.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Xamarin.UITest" />
|
||||
<PackageReference Include="xunit.v3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
<PackageReference Include="coverlet.collector" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue