Skip to content

Commit fea7c1e

Browse files
committed
Split mobile.Tests.ps1 -> ios.Tests.ps1 vs. android.Tests.ps1
1 parent 73274fb commit fea7c1e

File tree

5 files changed

+276
-260
lines changed

5 files changed

+276
-260
lines changed

.github/workflows/device-tests-android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
disk-size: ${{ env.ANDROID_EMULATOR_DISK_SIZE }}
145145
emulator-options: ${{ env.ANDROID_EMULATOR_OPTIONS }}
146146
disable-animations: false
147-
script: pwsh integration-test/mobile.Tests.ps1
147+
script: pwsh integration-test/android.Tests.ps1
148148

149149
- name: Retry Integration Tests (if previous failed to run)
150150
if: steps.first-integration-test-run.outcome == 'failure'
@@ -159,7 +159,7 @@ jobs:
159159
disk-size: ${{ env.ANDROID_EMULATOR_DISK_SIZE }}
160160
emulator-options: ${{ env.ANDROID_EMULATOR_OPTIONS }}
161161
disable-animations: false
162-
script: pwsh integration-test/mobile.Tests.ps1
162+
script: pwsh integration-test/android.Tests.ps1
163163

164164
- name: Upload results
165165
if: success() || failure()

.github/workflows/device-tests-ios.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ jobs:
4848
continue-on-error: true
4949
uses: getsentry/github-workflows/sentry-cli/integration-test/@a5e409bd5bad4c295201cdcfe862b17c50b29ab7 # v2.14.1
5050
with:
51-
path: integration-test/mobile.Tests.ps1
51+
path: integration-test/ios.Tests.ps1
5252

5353
- name: Retry Integration Tests (if previous failed to run)
5454
if: steps.first-integration-test-run.outcome == 'failure'
5555
uses: getsentry/github-workflows/sentry-cli/integration-test/@a5e409bd5bad4c295201cdcfe862b17c50b29ab7 # v2.14.1
5656
with:
57-
path: integration-test/mobile.Tests.ps1
57+
path: integration-test/ios.Tests.ps1
5858

5959
- name: Upload results
6060
if: success() || failure()

integration-test/android.Tests.ps1

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# This file contains test cases for https://pester.dev/
2+
Set-StrictMode -Version Latest
3+
$ErrorActionPreference = 'Stop'
4+
. $PSScriptRoot/pester.ps1
5+
. $PSScriptRoot/../scripts/device-test-utils.ps1
6+
7+
BeforeDiscovery {
8+
# Skip Android integration tests unless an emulator has been already started
9+
# by Android Device Tests, or manually when testing locally. This avoids
10+
# slowing down non-Device Test CI builds further.
11+
$script:emulator = Get-AndroidEmulatorId
12+
}
13+
14+
Describe 'MAUI app' -ForEach @(
15+
@{ tfm = "net9.0-android35.0" }
16+
) -Skip:(-not $script:emulator) {
17+
BeforeAll {
18+
. $PSScriptRoot/../scripts/device-test-utils.ps1
19+
Install-XHarness
20+
21+
Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue
22+
Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force
23+
Push-Location $PSScriptRoot/mobile-app
24+
25+
function InstallAndroidApp
26+
{
27+
param([string] $Dsn)
28+
$dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
29+
30+
# replace {{SENTRY_DSN}} in MauiProgram.cs
31+
(Get-Content MauiProgram.cs) `
32+
-replace '\{\{SENTRY_DSN\}\}', $dsn `
33+
| Set-Content MauiProgram.cs
34+
35+
$arch = ($(uname -m) -eq 'arm64') ? 'arm64' : 'x64'
36+
$rid = "android-$arch"
37+
38+
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
39+
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
40+
--configuration Release `
41+
--framework $tfm `
42+
--runtime $rid
43+
| ForEach-Object { Write-Host $_ }
44+
$LASTEXITCODE | Should -Be 0
45+
Write-Host '::endgroup::'
46+
47+
Write-Host "::group::Install bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk"
48+
xharness android install -v `
49+
--app bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk `
50+
--package-name io.sentry.dotnet.maui.device.integrationtestapp `
51+
--output-directory=integration_test_output
52+
| ForEach-Object { Write-Host $_ }
53+
$LASTEXITCODE | Should -Be 0
54+
Write-Host '::endgroup::'
55+
}
56+
57+
function RunAndroidApp
58+
{
59+
param(
60+
[string] $Dsn,
61+
[string] $CrashType = 'None',
62+
[string] $TestAction = 'None'
63+
)
64+
65+
# Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator
66+
$port = $Dsn.Split(':')[2].Split('/')[0]
67+
xharness android adb -v -- reverse tcp:$port tcp:$port
68+
69+
Write-Host "::group::Run Android app"
70+
xharness android adb -v `
71+
-- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity `
72+
-e SENTRY_CRASH_TYPE $CrashType `
73+
-e SENTRY_TEST_ACTION $TestAction
74+
| ForEach-Object { Write-Host $_ }
75+
$LASTEXITCODE | Should -Be 0
76+
77+
do
78+
{
79+
Write-Host "Waiting for app..."
80+
Start-Sleep -Seconds 1
81+
82+
$procid = (& adb shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', ''
83+
$activity = (& adb shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp"
84+
85+
} while ($procid -and $activity)
86+
87+
xharness android adb -v -- reverse --remove tcp:$port
88+
Write-Host '::endgroup::'
89+
}
90+
91+
function UninstallAndroidApp
92+
{
93+
Write-Host "::group::Uninstall io.sentry.dotnet.maui.device.integrationtestapp"
94+
xharness android uninstall -v `
95+
--package-name io.sentry.dotnet.maui.device.integrationtestapp
96+
| ForEach-Object { Write-Host $_ }
97+
$LASTEXITCODE | Should -Be 0
98+
Write-Host '::endgroup::'
99+
}
100+
}
101+
102+
AfterAll {
103+
Pop-Location
104+
}
105+
106+
AfterEach {
107+
UninstallAndroidApp
108+
}
109+
110+
It 'Managed crash' {
111+
$result = Invoke-SentryServer {
112+
param([string]$url)
113+
InstallAndroidApp -Dsn $url
114+
RunAndroidApp -Dsn $url -CrashType "Managed"
115+
RunAndroidApp -Dsn $url -TestAction "Exit"
116+
}
117+
118+
$result.HasErrors() | Should -BeFalse
119+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
120+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`""
121+
}
122+
123+
It 'Java crash' {
124+
$result = Invoke-SentryServer {
125+
param([string]$url)
126+
InstallAndroidApp -Dsn $url
127+
RunAndroidApp -Dsn $url -CrashType "Java"
128+
RunAndroidApp -Dsn $url -TestAction "Exit"
129+
}
130+
131+
$result.HasErrors() | Should -BeFalse
132+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"RuntimeException`""
133+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
134+
}
135+
136+
It 'Null reference exception' {
137+
$result = Invoke-SentryServer {
138+
param([string]$url)
139+
InstallAndroidApp -Dsn $url
140+
RunAndroidApp -Dsn $url -TestAction "NullReferenceException"
141+
RunAndroidApp -Dsn $url -TestAction "Exit"
142+
}
143+
144+
$result.HasErrors() | Should -BeFalse
145+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
146+
# TODO: fix redundant RuntimeException (#3954)
147+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw
148+
}
149+
}

integration-test/ios.Tests.ps1

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# This file contains test cases for https://pester.dev/
2+
Set-StrictMode -Version Latest
3+
$ErrorActionPreference = 'Stop'
4+
. $PSScriptRoot/pester.ps1
5+
. $PSScriptRoot/../scripts/device-test-utils.ps1
6+
7+
BeforeDiscovery {
8+
# Skip iOS integration tests unless a simulator has already been booted by
9+
# iOS Device Tests, or manually when testing locally. This avoids slowing
10+
# down the macOS build job further.
11+
$script:simulator = Get-IosSimulatorUdid -PreferredStates @('Booted')
12+
}
13+
14+
Describe 'iOS app (<tfm>)' -ForEach @(
15+
@{ tfm = "net9.0-ios18.0" }
16+
) -Skip:(-not $IsMacOS -or -not $script:simulator) {
17+
BeforeAll {
18+
. $PSScriptRoot/../scripts/device-test-utils.ps1
19+
Install-XHarness
20+
21+
Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue
22+
Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force
23+
Push-Location $PSScriptRoot/mobile-app
24+
25+
$arch = ($(uname -m) -eq 'arm64') ? 'arm64' : 'x64'
26+
$rid = "iossimulator-$arch"
27+
$arguments = @(
28+
"-v",
29+
"--target=ios-simulator-64",
30+
"--device=$simulator",
31+
"--output-directory=integration_test_output",
32+
"--timeout=00:10:00"
33+
)
34+
35+
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
36+
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
37+
--configuration Release `
38+
--framework $tfm `
39+
--runtime $rid
40+
| ForEach-Object { Write-Host $_ }
41+
$LASTEXITCODE | Should -Be 0
42+
Write-Host '::endgroup::'
43+
44+
function RunIosApp
45+
{
46+
param(
47+
[string] $Dsn,
48+
[string] $CrashType = 'None',
49+
[string] $TestAction = 'None'
50+
)
51+
$Dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
52+
Write-Host "::group::Run app (Crash=$CrashType, Action=$TestAction)"
53+
xharness apple just-run $arguments `
54+
--app io.sentry.dotnet.maui.device.integrationtestapp `
55+
--set-env SENTRY_DSN=$Dsn `
56+
--set-env SENTRY_CRASH_TYPE=$CrashType `
57+
--set-env SENTRY_TEST_ACTION=$TestAction
58+
| ForEach-Object { Write-Host $_ }
59+
$LASTEXITCODE | Should -Be 0
60+
Write-Host '::endgroup::'
61+
}
62+
}
63+
64+
AfterAll {
65+
Pop-Location
66+
}
67+
68+
BeforeEach {
69+
Write-Host "::group::Install bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app"
70+
xharness apple install $arguments `
71+
--app bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app
72+
| ForEach-Object { Write-Host $_ }
73+
$LASTEXITCODE | Should -Be 0
74+
Write-Host '::endgroup::'
75+
}
76+
77+
AfterEach {
78+
Write-Host "::group::Uninstall io.sentry.dotnet.maui.device.integrationtestapp"
79+
xharness apple uninstall $arguments `
80+
--app io.sentry.dotnet.maui.device.integrationtestapp
81+
| ForEach-Object { Write-Host $_ }
82+
$LASTEXITCODE | Should -Be 0
83+
Write-Host '::endgroup::'
84+
}
85+
86+
It 'captures managed crash' {
87+
$result = Invoke-SentryServer {
88+
param([string]$url)
89+
RunIosApp -Dsn $url -CrashType "Managed"
90+
RunIosApp -Dsn $url -TestAction "Exit"
91+
}
92+
93+
$result.HasErrors() | Should -BeFalse
94+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
95+
# TODO: fix redundant SIGABRT (#3954)
96+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" } | Should -Throw
97+
}
98+
99+
It 'captures native crash' {
100+
$result = Invoke-SentryServer {
101+
param([string]$url)
102+
RunIosApp -Dsn $url -CrashType "Native"
103+
RunIosApp -Dsn $url -TestAction "Exit"
104+
}
105+
106+
$result.HasErrors() | Should -BeFalse
107+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"EXC_[A-Z_]+`""
108+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
109+
}
110+
111+
It 'captures null reference exception' {
112+
$result = Invoke-SentryServer {
113+
param([string]$url)
114+
RunIosApp -Dsn $url -TestAction "NullReferenceException"
115+
RunIosApp -Dsn $url -TestAction "Exit"
116+
}
117+
118+
$result.HasErrors() | Should -BeFalse
119+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
120+
# TODO: fix redundant EXC_BAD_ACCESS (#3954)
121+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw
122+
}
123+
}

0 commit comments

Comments
 (0)