Skip to content

Commit dd23c13

Browse files
committed
Run Android integration tests in Release and Debug modes
1 parent a267d32 commit dd23c13

File tree

5 files changed

+62
-61
lines changed

5 files changed

+62
-61
lines changed

integration-test/android.Tests.ps1

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,31 @@ BeforeDiscovery {
1313
}
1414

1515
Describe 'MAUI app' -ForEach @(
16-
@{ tfm = "net9.0-android35.0" }
16+
@{ tfm = "net9.0-android35.0"; configuration = "Release" }
17+
@{ tfm = "net9.0-android35.0"; configuration = "Debug" }
1718
) -Skip:(-not $script:emulator) {
1819
BeforeAll {
1920
Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue
2021
Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force
2122
Push-Location $PSScriptRoot/mobile-app
2223

23-
function InstallAndroidApp
24-
{
25-
param([string] $Dsn)
26-
$dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
24+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
25+
$rid = "android-$arch"
2726

28-
# replace {{SENTRY_DSN}} in MauiProgram.cs
29-
(Get-Content MauiProgram.cs) `
30-
-replace '\{\{SENTRY_DSN\}\}', $dsn `
31-
| Set-Content MauiProgram.cs
32-
33-
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
34-
$rid = "android-$arch"
35-
36-
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
37-
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
38-
--configuration Release `
39-
--framework $tfm `
40-
--runtime $rid
41-
| ForEach-Object { Write-Host $_ }
42-
Write-Host '::endgroup::'
43-
$LASTEXITCODE | Should -Be 0
27+
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
28+
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
29+
--configuration $configuration `
30+
--framework $tfm `
31+
--runtime $rid
32+
| ForEach-Object { Write-Host $_ }
33+
Write-Host '::endgroup::'
34+
$LASTEXITCODE | Should -Be 0
4435

45-
Write-Host "::group::Install bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk"
36+
function InstallAndroidApp
37+
{
38+
Write-Host "::group::Install bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk"
4639
xharness android install -v `
47-
--app bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk `
40+
--app bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk `
4841
--package-name io.sentry.dotnet.maui.device.integrationtestapp `
4942
--output-directory=test_output
5043
| ForEach-Object { Write-Host $_ }
@@ -58,35 +51,25 @@ Describe 'MAUI app' -ForEach @(
5851
[string] $Dsn,
5952
[string] $TestArg = 'None'
6053
)
54+
Write-Host "::group::Run Android app (TestArg=$TestArg)"
55+
$dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
56+
xharness android adb -v `
57+
-- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity `
58+
-e SENTRY_DSN $dsn `
59+
-e SENTRY_TEST_ARG $TestArg
60+
| ForEach-Object { Write-Host $_ }
61+
Write-Host '::endgroup::'
62+
$LASTEXITCODE | Should -Be 0
6163

62-
try
64+
do
6365
{
64-
# Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator
65-
$port = $Dsn.Split(':')[2].Split('/')[0]
66-
xharness android adb -v -- reverse tcp:$port tcp:$port
67-
68-
Write-Host "::group::Run Android app (TestArg=$TestArg)"
69-
xharness android adb -v `
70-
-- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity `
71-
-e SENTRY_TEST_ARG $TestArg
72-
| ForEach-Object { Write-Host $_ }
73-
Write-Host '::endgroup::'
74-
$LASTEXITCODE | Should -Be 0
66+
Write-Host "Waiting for app..."
67+
Start-Sleep -Seconds 1
7568

76-
do
77-
{
78-
Write-Host "Waiting for app..."
79-
Start-Sleep -Seconds 1
69+
$procid = (& xharness android adb -- shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', ''
70+
$activity = (& xharness android adb -- shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp"
8071

81-
$procid = (& xharness android adb -- shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', ''
82-
$activity = (& xharness android adb -- shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp"
83-
84-
} while ($procid -and $activity)
85-
}
86-
finally
87-
{
88-
xharness android adb -v -- reverse --remove-all
89-
}
72+
} while ($procid -and $activity)
9073
}
9174

9275
function UninstallAndroidApp
@@ -111,20 +94,27 @@ Describe 'MAUI app' -ForEach @(
11194
Write-Host '::endgroup::'
11295
}
11396
}
97+
98+
# Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator
99+
xharness android adb -v -- reverse tcp:8000 tcp:8000
114100
}
115101

116102
AfterAll {
117103
Pop-Location
104+
xharness android adb -v -- reverse --remove tcp:8000
105+
}
106+
107+
BeforeEach {
108+
InstallAndroidApp
118109
}
119110

120111
AfterEach {
121112
UninstallAndroidApp
122113
}
123114

124-
It 'Managed crash' {
115+
It "Managed crash ($configuration)" {
125116
$result = Invoke-SentryServer {
126117
param([string]$url)
127-
InstallAndroidApp -Dsn $url
128118
RunAndroidApp -Dsn $url -TestArg "Managed"
129119
RunAndroidApp -Dsn $url
130120
}
@@ -133,12 +123,12 @@ Describe 'MAUI app' -ForEach @(
133123
$result.HasErrors() | Should -BeFalse
134124
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
135125
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`""
126+
$result.Envelopes() | Should -HaveCount 1
136127
}
137128

138-
It 'Java crash' {
129+
It "Java crash ($configuration)" {
139130
$result = Invoke-SentryServer {
140131
param([string]$url)
141-
InstallAndroidApp -Dsn $url
142132
RunAndroidApp -Dsn $url -TestArg "Java"
143133
RunAndroidApp -Dsn $url
144134
}
@@ -147,12 +137,12 @@ Describe 'MAUI app' -ForEach @(
147137
$result.HasErrors() | Should -BeFalse
148138
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"RuntimeException`""
149139
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
140+
$result.Envelopes() | Should -HaveCount 1
150141
}
151142

152-
It 'Native crash' {
143+
It "Native crash ($configuration)" {
153144
$result = Invoke-SentryServer {
154145
param([string]$url)
155-
InstallAndroidApp -Dsn $url
156146
RunAndroidApp -Dsn $url -TestArg "Native"
157147
RunAndroidApp -Dsn $url
158148
}
@@ -161,20 +151,25 @@ Describe 'MAUI app' -ForEach @(
161151
$result.HasErrors() | Should -BeFalse
162152
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"SIG[A-Z]+`"" # SIGILL (x86_64), SIGTRAP (arm64-v8a)
163153
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
154+
$result.Envelopes() | Should -HaveCount 1
164155
}
165156

166-
It 'Null reference exception' {
157+
It "Null reference exception ($configuration)" {
167158
$result = Invoke-SentryServer {
168159
param([string]$url)
169-
InstallAndroidApp -Dsn $url
170160
RunAndroidApp -Dsn $url -TestArg "NullReferenceException"
171161
RunAndroidApp -Dsn $url
172162
}
173163

174164
Dump-ServerErrors -Result $result
175165
$result.HasErrors() | Should -BeFalse
176166
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
177-
# TODO: fix redundant RuntimeException (#3954)
178-
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw
167+
# TODO: fix redundant SIGSEGV in Release (#3954)
168+
if ($configuration -eq 'Release') {
169+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw
170+
} else {
171+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`""
172+
$result.Envelopes() | Should -HaveCount 1
173+
}
179174
}
180175
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected override void OnAppearing()
3939

4040
SentrySdk.Close();
4141
#if ANDROID
42+
Platform.CurrentActivity.FinishAffinity();
4243
Process.KillProcess(Process.MyPid());
4344
#elif IOS
4445
System.Environment.Exit(0);

integration-test/net9-maui/MauiProgram.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ public static MauiApp CreateMauiApp()
1212
.UseMauiApp<App>()
1313
.UseSentry(options =>
1414
{
15-
#if ANDROID
16-
options.Dsn = "{{SENTRY_DSN}}";
17-
#endif
15+
options.Dsn = System.Environment.GetEnvironmentVariable("SENTRY_DSN") ?? "http://[email protected]:8000/0";
1816
options.Debug = false;
1917
options.DiagnosticLevel = SentryLevel.Error;
18+
// predictable crash envelopes only
19+
options.SendClientReports = false;
20+
options.AutoSessionTracking = false;
2021
})
2122
.ConfigureFonts(fonts =>
2223
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ protected override void OnCreate(Bundle? savedInstanceState)
1818
{
1919
base.OnCreate(savedInstanceState);
2020

21+
System.Environment.SetEnvironmentVariable("SENTRY_DSN", Intent?.GetStringExtra("SENTRY_DSN"));
2122
System.Environment.SetEnvironmentVariable("SENTRY_TEST_ARG", Intent?.GetStringExtra("SENTRY_TEST_ARG"));
2223
}
2324
}

integration-test/net9-maui/Sentry.Maui.Device.IntegrationTestApp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<MtouchUseLlvm>false</MtouchUseLlvm>
1717
<EnableAssemblyILStripping>false</EnableAssemblyILStripping>
1818

19+
<!-- https://github.com/dotnet/android/wiki/Diagnose-Fast-Deployment-Issues -->
20+
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
21+
1922
<!-- Display name -->
2023
<ApplicationTitle>Sentry.Maui.Device.IntegrationTestApp</ApplicationTitle>
2124

0 commit comments

Comments
 (0)