Skip to content

Commit 382fa2e

Browse files
authored
test: run mobile integration tests in Release and Debug modes (#4666)
1 parent 5c4f9e1 commit 382fa2e

File tree

6 files changed

+85
-68
lines changed

6 files changed

+85
-68
lines changed

integration-test/android.Tests.ps1

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,37 @@ BeforeDiscovery {
1212
$script:emulator = Get-AndroidEmulatorId
1313
}
1414

15-
Describe 'MAUI app' -ForEach @(
16-
@{ tfm = "net9.0-android35.0" }
15+
Describe 'MAUI app (<tfm>, <configuration>)' -ForEach @(
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+
# replace {{SENTRY_DSN}} in MauiProgram.cs
25+
(Get-Content MauiProgram.cs) `
26+
-replace '\{\{SENTRY_DSN\}\}', 'http://key@127.0.0.1:8000/0' `
27+
| Set-Content MauiProgram.cs
2728

28-
# replace {{SENTRY_DSN}} in MauiProgram.cs
29-
(Get-Content MauiProgram.cs) `
30-
-replace '\{\{SENTRY_DSN\}\}', $dsn `
31-
| Set-Content MauiProgram.cs
29+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
30+
$rid = "android-$arch"
3231

33-
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
34-
$rid = "android-$arch"
32+
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
33+
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
34+
--configuration $configuration `
35+
--framework $tfm `
36+
--runtime $rid
37+
| ForEach-Object { Write-Host $_ }
38+
Write-Host '::endgroup::'
39+
$LASTEXITCODE | Should -Be 0
3540

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
44-
45-
Write-Host "::group::Install bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk"
41+
function InstallAndroidApp
42+
{
43+
Write-Host "::group::Install bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk"
4644
xharness android install -v `
47-
--app bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk `
45+
--app bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk `
4846
--package-name io.sentry.dotnet.maui.device.integrationtestapp `
4947
--output-directory=test_output
5048
| ForEach-Object { Write-Host $_ }
@@ -58,35 +56,25 @@ Describe 'MAUI app' -ForEach @(
5856
[string] $Dsn,
5957
[string] $TestArg = 'None'
6058
)
59+
Write-Host "::group::Run Android app (TestArg=$TestArg)"
60+
$dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
61+
xharness android adb -v `
62+
-- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity `
63+
-e SENTRY_DSN $dsn `
64+
-e SENTRY_TEST_ARG $TestArg
65+
| ForEach-Object { Write-Host $_ }
66+
Write-Host '::endgroup::'
67+
$LASTEXITCODE | Should -Be 0
6168

62-
try
69+
do
6370
{
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
71+
Write-Host "Waiting for app..."
72+
Start-Sleep -Seconds 1
7573

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

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-
}
77+
} while ($procid -and $activity)
9078
}
9179

9280
function UninstallAndroidApp
@@ -111,20 +99,27 @@ Describe 'MAUI app' -ForEach @(
11199
Write-Host '::endgroup::'
112100
}
113101
}
102+
103+
# Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator
104+
xharness android adb -v -- reverse tcp:8000 tcp:8000
114105
}
115106

116107
AfterAll {
117108
Pop-Location
109+
xharness android adb -v -- reverse --remove tcp:8000
110+
}
111+
112+
BeforeEach {
113+
InstallAndroidApp
118114
}
119115

120116
AfterEach {
121117
UninstallAndroidApp
122118
}
123119

124-
It 'Managed crash' {
120+
It 'Managed crash (<configuration>)' {
125121
$result = Invoke-SentryServer {
126122
param([string]$url)
127-
InstallAndroidApp -Dsn $url
128123
RunAndroidApp -Dsn $url -TestArg "Managed"
129124
RunAndroidApp -Dsn $url
130125
}
@@ -133,12 +128,12 @@ Describe 'MAUI app' -ForEach @(
133128
$result.HasErrors() | Should -BeFalse
134129
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
135130
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`""
131+
$result.Envelopes() | Should -HaveCount 1
136132
}
137133

138-
It 'Java crash' {
134+
It 'Java crash (<configuration>)' {
139135
$result = Invoke-SentryServer {
140136
param([string]$url)
141-
InstallAndroidApp -Dsn $url
142137
RunAndroidApp -Dsn $url -TestArg "Java"
143138
RunAndroidApp -Dsn $url
144139
}
@@ -147,12 +142,12 @@ Describe 'MAUI app' -ForEach @(
147142
$result.HasErrors() | Should -BeFalse
148143
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"RuntimeException`""
149144
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
145+
$result.Envelopes() | Should -HaveCount 1
150146
}
151147

152-
It 'Native crash' {
148+
It 'Native crash (<configuration>)' {
153149
$result = Invoke-SentryServer {
154150
param([string]$url)
155-
InstallAndroidApp -Dsn $url
156151
RunAndroidApp -Dsn $url -TestArg "Native"
157152
RunAndroidApp -Dsn $url
158153
}
@@ -161,20 +156,25 @@ Describe 'MAUI app' -ForEach @(
161156
$result.HasErrors() | Should -BeFalse
162157
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"SIG[A-Z]+`"" # SIGILL (x86_64), SIGTRAP (arm64-v8a)
163158
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
159+
$result.Envelopes() | Should -HaveCount 1
164160
}
165161

166-
It 'Null reference exception' {
162+
It 'Null reference exception (<configuration>)' {
167163
$result = Invoke-SentryServer {
168164
param([string]$url)
169-
InstallAndroidApp -Dsn $url
170165
RunAndroidApp -Dsn $url -TestArg "NullReferenceException"
171166
RunAndroidApp -Dsn $url
172167
}
173168

174169
Dump-ServerErrors -Result $result
175170
$result.HasErrors() | Should -BeFalse
176171
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
177-
# TODO: fix redundant RuntimeException (#3954)
178-
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw
172+
# TODO: fix redundant SIGSEGV in Release (#3954)
173+
if ($configuration -eq "Release") {
174+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw
175+
} else {
176+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`""
177+
$result.Envelopes() | Should -HaveCount 1
178+
}
179179
}
180180
}

integration-test/ios.Tests.ps1

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ BeforeDiscovery {
1111
$script:simulator = Get-IosSimulatorUdid -PreferredStates @('Booted')
1212
}
1313

14-
Describe 'iOS app (<tfm>)' -ForEach @(
15-
@{ tfm = "net9.0-ios18.0" }
14+
Describe 'iOS app (<tfm>, <configuration>)' -ForEach @(
15+
@{ tfm = "net9.0-ios18.0"; configuration = "Release" }
16+
@{ tfm = "net9.0-ios18.0"; configuration = "Debug" }
1617
) -Skip:(-not $script:simulator) {
1718
BeforeAll {
1819
. $PSScriptRoot/../scripts/device-test-utils.ps1
@@ -26,7 +27,7 @@ Describe 'iOS app (<tfm>)' -ForEach @(
2627

2728
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
2829
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
29-
--configuration Release `
30+
--configuration $configuration `
3031
--framework $tfm `
3132
--runtime $rid
3233
| ForEach-Object { Write-Host $_ }
@@ -35,9 +36,9 @@ Describe 'iOS app (<tfm>)' -ForEach @(
3536

3637
function InstallIosApp
3738
{
38-
Write-Host "::group::Install bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app"
39+
Write-Host "::group::Install bin/$configuration/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app"
3940
xcrun simctl install $simulator `
40-
bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app
41+
bin/$configuration/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app
4142
| ForEach-Object { Write-Host $_ }
4243
Write-Host '::endgroup::'
4344
$LASTEXITCODE | Should -Be 0
@@ -86,7 +87,7 @@ Describe 'iOS app (<tfm>)' -ForEach @(
8687
UninstallIosApp
8788
}
8889

89-
It 'captures managed crash' {
90+
It 'captures managed crash (<configuration>)' {
9091
$result = Invoke-SentryServer {
9192
param([string]$url)
9293
RunIosApp -Dsn $url -TestArg "Managed"
@@ -97,9 +98,10 @@ Describe 'iOS app (<tfm>)' -ForEach @(
9798
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
9899
# TODO: fix redundant SIGABRT (#3954)
99100
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" } | Should -Throw
101+
{ $result.Envelopes() | Should -HaveCount 1 } | Should -Throw
100102
}
101103

102-
It 'captures native crash' {
104+
It 'captures native crash (<configuration>)' {
103105
$result = Invoke-SentryServer {
104106
param([string]$url)
105107
RunIosApp -Dsn $url -TestArg "Native"
@@ -109,9 +111,10 @@ Describe 'iOS app (<tfm>)' -ForEach @(
109111
$result.HasErrors() | Should -BeFalse
110112
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"EXC_[A-Z_]+`""
111113
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
114+
$result.Envelopes() | Should -HaveCount 1
112115
}
113116

114-
It 'captures null reference exception' {
117+
It 'captures null reference exception (<configuration>)' {
115118
$result = Invoke-SentryServer {
116119
param([string]$url)
117120
RunIosApp -Dsn $url -TestArg "NullReferenceException"
@@ -120,7 +123,12 @@ Describe 'iOS app (<tfm>)' -ForEach @(
120123

121124
$result.HasErrors() | Should -BeFalse
122125
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
123-
# TODO: fix redundant EXC_BAD_ACCESS (#3954)
124-
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw
126+
# TODO: fix redundant EXC_BAD_ACCESS in Release (#3954)
127+
if ($configuration -eq 'Release') {
128+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw
129+
} else {
130+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`""
131+
$result.Envelopes() | Should -HaveCount 1
132+
}
125133
}
126134
}

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

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

4040
SentrySdk.Close();
4141
#if ANDROID
42+
// prevent auto-restart
43+
Platform.CurrentActivity?.FinishAffinity();
4244
Process.KillProcess(Process.MyPid());
4345
#elif IOS
4446
System.Environment.Exit(0);

integration-test/net9-maui/MauiProgram.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static MauiApp CreateMauiApp()
1717
#endif
1818
options.Debug = false;
1919
options.DiagnosticLevel = SentryLevel.Error;
20+
// predictable crash envelopes only
21+
options.SendClientReports = false;
22+
options.AutoSessionTracking = false;
2023
})
2124
.ConfigureFonts(fonts =>
2225
{

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)