Skip to content

Commit bb7b598

Browse files
committed
Add integration test
1 parent 8b1e9c6 commit bb7b598

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

integration-test/android.Tests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,18 @@ Describe 'MAUI app (<tfm>, <configuration>)' -ForEach @(
201201
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"system`",`"thread_id`":`"1`",`"category`":`"network.event`",`"action`":`"NETWORK_CAPABILITIES_CHANGED`""
202202
$result.Envelopes() | Should -HaveCount 1
203203
}
204+
205+
It 'Lifecycle events (<configuration>)' {
206+
$result = Invoke-SentryServer {
207+
param([string]$url)
208+
RunAndroidApp -Dsn $url -TestArg "Background"
209+
}
210+
211+
Dump-ServerErrors -Result $result
212+
$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`""
215+
}
216+
$result.Envelopes() | Should -HaveCount 1
217+
}
204218
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public App()
1515
InitializeComponent();
1616
}
1717

18-
private static bool HasTestArg(string arg)
18+
public static bool HasTestArg(string arg)
1919
{
2020
return string.Equals(testArg, arg, StringComparison.OrdinalIgnoreCase);
2121
}
@@ -91,6 +91,12 @@ public static void OnAppearing()
9191
CaptureSystemBreadcrumb(testArg, breadcrumb);
9292
Kill();
9393
}
94+
else if (HasTestArg("Background"))
95+
{
96+
#if ANDROID
97+
Platform.CurrentActivity?.MoveTaskToBack(true);
98+
#endif
99+
}
94100
else if (HasTestArg("None"))
95101
{
96102
Kill();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ protected override void OnCreate(Bundle? savedInstanceState)
2121
System.Environment.SetEnvironmentVariable("SENTRY_DSN", Intent?.GetStringExtra("SENTRY_DSN"));
2222
System.Environment.SetEnvironmentVariable("SENTRY_TEST_ARG", Intent?.GetStringExtra("SENTRY_TEST_ARG"));
2323
}
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+
}
34+
}
2435
}

0 commit comments

Comments
 (0)