-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathandroid.Tests.ps1
More file actions
207 lines (177 loc) · 7.72 KB
/
android.Tests.ps1
File metadata and controls
207 lines (177 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
param(
[string] $dotnet_version = "net10.0"
)
# This file contains test cases for https://pester.dev/
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
. $PSScriptRoot/pester.ps1
. $PSScriptRoot/common.ps1
. $PSScriptRoot/../scripts/device-test-utils.ps1
BeforeDiscovery {
# Skip Android integration tests unless an emulator has been already started
# by Android Device Tests, or manually when testing locally. This avoids
# slowing down non-Device Test CI builds further.
Install-XHarness
$script:emulator = Get-AndroidEmulatorId
}
$cases = @(
@{ configuration = 'Release' }
@{ configuration = 'Debug' }
)
Describe 'MAUI app (<dotnet_version>, <configuration>)' -ForEach $cases -Skip:(-not $script:emulator) {
BeforeAll {
$tfm = "$dotnet_version-android$(GetAndroidTpv $dotnet_version)"
Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force
Push-Location $PSScriptRoot/mobile-app
# replace {{SENTRY_DSN}} in MauiProgram.cs
(Get-Content MauiProgram.cs) `
-replace '\{\{SENTRY_DSN\}\}', 'http://key@127.0.0.1:8000/0' `
| Set-Content MauiProgram.cs
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
$rid = "android-$arch"
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
--configuration $configuration `
--framework $tfm `
--runtime $rid
| ForEach-Object { Write-Host $_ }
Write-Host '::endgroup::'
$LASTEXITCODE | Should -Be 0
function InstallAndroidApp
{
Write-Host "::group::Install bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk"
xharness android install -v `
--app bin/$configuration/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk `
--package-name io.sentry.dotnet.maui.device.integrationtestapp `
--output-directory=test_output
| ForEach-Object { Write-Host $_ }
Write-Host '::endgroup::'
$LASTEXITCODE | Should -Be 0
}
function RunAndroidApp
{
param(
[string] $Dsn,
[string] $TestArg = 'None'
)
Write-Host "::group::Run Android app (TestArg=$TestArg)"
$dsn = $Dsn.Replace('http://', 'http://key@') + '/0'
xharness android adb -v `
-- shell am start -S -n io.sentry.dotnet.maui.device.integrationtestapp/.MainActivity `
-e SENTRY_DSN $dsn `
-e SENTRY_TEST_ARG $TestArg
| ForEach-Object { Write-Host $_ }
Write-Host '::endgroup::'
$LASTEXITCODE | Should -Be 0
do
{
Write-Host "Waiting for app..."
Start-Sleep -Seconds 1
$procid = (& xharness android adb -- shell pidof "io.sentry.dotnet.maui.device.integrationtestapp") -replace '\s', ''
$activity = (& xharness android adb -- shell dumpsys activity activities) -match "io\.sentry\.dotnet\.maui\.device\.integrationtestapp"
} while ($procid -and $activity)
}
function UninstallAndroidApp
{
Write-Host "::group::Uninstall io.sentry.dotnet.maui.device.integrationtestapp"
xharness android uninstall -v `
--package-name io.sentry.dotnet.maui.device.integrationtestapp
| ForEach-Object { Write-Host $_ }
$LASTEXITCODE | Should -Be 0
Write-Host '::endgroup::'
}
# Helper to dump server stderr if the test server reported errors
function Dump-ServerErrors {
param(
[Parameter(Mandatory)]
$Result
)
if ($Result.HasErrors()) {
Write-Host '::group::sentry-server stderr'
$Result.ServerStdErr | ForEach-Object { Write-Host $_ }
Write-Host '::endgroup::'
}
}
# Setup port forwarding for accessing sentry-server at 127.0.0.1:8000 from the emulator
xharness android adb -v -- reverse tcp:8000 tcp:8000
}
AfterAll {
Pop-Location
xharness android adb -v -- reverse --remove tcp:8000
}
BeforeEach {
InstallAndroidApp
}
AfterEach {
UninstallAndroidApp
}
It 'Managed crash (<configuration>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunAndroidApp -Dsn $url -TestArg "Managed"
RunAndroidApp -Dsn $url
}
Dump-ServerErrors -Result $result
$result.HasErrors() | Should -BeFalse
$result.Events() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
$result.Events() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`""
$result.Events() | Should -HaveCount 1
}
It 'Java crash (<configuration>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunAndroidApp -Dsn $url -TestArg "Java"
RunAndroidApp -Dsn $url
}
Dump-ServerErrors -Result $result
$result.HasErrors() | Should -BeFalse
$result.Events() | Should -AnyElementMatch "`"type`":`"RuntimeException`""
$result.Events() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
$result.Events() | Should -HaveCount 1
}
It 'Native crash (<configuration>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunAndroidApp -Dsn $url -TestArg "Native"
RunAndroidApp -Dsn $url
}
Dump-ServerErrors -Result $result
$result.HasErrors() | Should -BeFalse
$result.Events() | Should -AnyElementMatch "`"type`":`"SIGSEGV`""
$result.Events() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
$result.Events() | Should -HaveCount 1
}
It 'Null reference exception (<configuration>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunAndroidApp -Dsn $url -TestArg "NullReferenceException"
RunAndroidApp -Dsn $url
}
Dump-ServerErrors -Result $result
$result.HasErrors() | Should -BeFalse
$result.Events() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
$result.Events() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`""
$result.Events() | Should -HaveCount 1
}
It 'Delivers battery breadcrumbs in main thread (<configuration>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunAndroidApp -Dsn $url -TestArg "BATTERY_CHANGED"
}
Dump-ServerErrors -Result $result
$result.HasErrors() | Should -BeFalse
$result.Events() | Should -AnyElementMatch "`"type`":`"system`",`"thread_id`":`"1`",`"category`":`"device.event`",`"action`":`"BATTERY_CHANGED`""
$result.Events() | Should -HaveCount 1
}
It 'Delivers network breadcrumbs in main thread (<configuration>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunAndroidApp -Dsn $url -TestArg "NETWORK_CAPABILITIES_CHANGED"
}
Dump-ServerErrors -Result $result
$result.HasErrors() | Should -BeFalse
$result.Events() | Should -AnyElementMatch "`"type`":`"system`",`"thread_id`":`"1`",`"category`":`"network.event`",`"action`":`"NETWORK_CAPABILITIES_CHANGED`""
$result.Events() | Should -HaveCount 1
}
}