Skip to content

Commit d7332b8

Browse files
committed
Revise integration test
1 parent d6fe871 commit d7332b8

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

integration-test/android.Tests.ps1

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ Describe 'MAUI app (<tfm>, <configuration>)' -ForEach @(
5454
{
5555
param(
5656
[string] $Dsn,
57-
[string] $TestArg = 'None'
57+
[string] $TestArg = 'None',
58+
[string] $TestCondition = 'OnAppearing',
59+
[scriptblock] $Callback = $null
5860
)
5961
Write-Host "::group::Run Android app (TestArg=$TestArg)"
6062
$dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
6163
xharness android adb -v `
6264
-- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity `
6365
-e SENTRY_DSN $dsn `
64-
-e SENTRY_TEST_ARG $TestArg
66+
-e SENTRY_TEST_ARG $TestArg `
67+
-e SENTRY_TEST_CONDITION $TestCondition
6568
| ForEach-Object { Write-Host $_ }
6669
Write-Host '::endgroup::'
6770
$LASTEXITCODE | Should -Be 0
@@ -73,7 +76,10 @@ Describe 'MAUI app (<tfm>, <configuration>)' -ForEach @(
7376

7477
$procid = (& xharness android adb -- shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', ''
7578
$activity = (& xharness android adb -- shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp"
76-
79+
if ($procid -and $activity -and $Callback)
80+
{
81+
& $Callback
82+
}
7783
} while ($procid -and $activity)
7884
}
7985

@@ -202,16 +208,36 @@ Describe 'MAUI app (<tfm>, <configuration>)' -ForEach @(
202208
$result.Envelopes() | Should -HaveCount 1
203209
}
204210

205-
It 'Lifecycle events (<configuration>)' {
211+
It 'Native native lifecycle events' {
212+
$result = Invoke-SentryServer {
213+
param([string]$url)
214+
RunAndroidApp -Dsn $url -TestArg $type -TestCondition "OnSleep" {
215+
xharness android adb -- shell input keyevent KEYCODE_HOME
216+
}
217+
RunAndroidApp -Dsn $url
218+
}
219+
220+
Dump-ServerErrors -Result $result
221+
$result.HasErrors() | Should -BeFalse
222+
@('created', 'started', 'resumed', 'paused') | ForEach-Object {
223+
# TODO: why is native breadcrumb data a string instead of object?
224+
$result.Envelopes() | Should -AnyElementMatch ('"type":"navigation","data":"{\"screen\":\"MainActivity\",\"state\":\"' + $_ + '\"}\","category":"ui.lifecycle"')
225+
}
226+
$result.Envelopes() | Should -HaveCount 1
227+
}
228+
229+
It 'Managed lifecycle events' {
206230
$result = Invoke-SentryServer {
207231
param([string]$url)
208-
RunAndroidApp -Dsn $url -TestArg "Background"
232+
RunAndroidApp -Dsn $url -TestArg $type -TestCondition "OnSleep" {
233+
xharness android adb -- shell input keyevent KEYCODE_HOME
234+
}
209235
}
210236

211237
Dump-ServerErrors -Result $result
212238
$result.HasErrors() | Should -BeFalse
213-
@('created', 'started', 'resumed', 'paused', 'stopped') | ForEach-Object {
214-
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"navigation`",`"data`":{`"screen`":`"MainActivity`",`"state`":`"$_`"},`"category`":`"ui.lifecycle`""
239+
@('created', 'started', 'resumed', 'paused') | ForEach-Object {
240+
$result.Envelopes() | Should -AnyElementMatch ('"type":"navigation","data":{"screen":"MainActivity","state":"' + $_ + '"},"category":"ui.lifecycle"')
215241
}
216242
$result.Envelopes() | Should -HaveCount 1
217243
}

integration-test/net9-maui/App.xaml.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public partial class App : Application
99
{
1010
private static readonly ConcurrentDictionary<string, Dictionary<string, string>> systemBreadcrumbs = new();
1111
private static string? testArg;
12+
private static string? testCondition;
1213

1314
public App()
1415
{
@@ -20,6 +21,11 @@ public static bool HasTestArg(string arg)
2021
return string.Equals(testArg, arg, StringComparison.OrdinalIgnoreCase);
2122
}
2223

24+
public static bool HasTestCondition(string condition)
25+
{
26+
return string.Equals(testCondition, condition, StringComparison.OrdinalIgnoreCase);
27+
}
28+
2329
public static void ReceiveSystemBreadcrumb(Breadcrumb breadcrumb)
2430
{
2531
if (breadcrumb.Type != "system" ||
@@ -64,7 +70,26 @@ protected override Window CreateWindow(IActivationState? activationState)
6470
public static void OnAppearing()
6571
{
6672
testArg = System.Environment.GetEnvironmentVariable("SENTRY_TEST_ARG");
73+
testCondition = System.Environment.GetEnvironmentVariable("SENTRY_TEST_CONDITION");
74+
75+
if (HasTestCondition("OnAppearing"))
76+
{
77+
RunTest();
78+
}
79+
}
80+
81+
protected override void OnSleep()
82+
{
83+
base.OnSleep();
6784

85+
if (HasTestCondition("OnSleep"))
86+
{
87+
RunTest();
88+
}
89+
}
90+
91+
private static void RunTest()
92+
{
6893
#pragma warning disable CS0618
6994
if (Enum.TryParse<CrashType>(testArg, ignoreCase: true, out var crashType))
7095
{
@@ -91,12 +116,6 @@ public static void OnAppearing()
91116
CaptureSystemBreadcrumb(testArg, breadcrumb);
92117
Kill();
93118
}
94-
else if (HasTestArg("Background"))
95-
{
96-
#if ANDROID
97-
Platform.CurrentActivity?.MoveTaskToBack(true);
98-
#endif
99-
}
100119
else if (HasTestArg("None"))
101120
{
102121
Kill();

integration-test/net9-maui/Platforms/Android/MainActivity.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ protected override void OnCreate(Bundle? savedInstanceState)
2020

2121
System.Environment.SetEnvironmentVariable("SENTRY_DSN", Intent?.GetStringExtra("SENTRY_DSN"));
2222
System.Environment.SetEnvironmentVariable("SENTRY_TEST_ARG", Intent?.GetStringExtra("SENTRY_TEST_ARG"));
23-
}
24-
25-
protected override void OnStop()
26-
{
27-
base.OnStop();
28-
29-
if (App.HasTestArg("Background"))
30-
{
31-
SentrySdk.CaptureMessage("Background");
32-
App.Kill();
33-
}
23+
System.Environment.SetEnvironmentVariable("SENTRY_TEST_CONDITION", Intent?.GetStringExtra("SENTRY_TEST_CONDITION"));
3424
}
3525
}

0 commit comments

Comments
 (0)