|
| 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 | + Install-XHarness |
| 12 | + $script:emulator = Get-AndroidEmulatorId |
| 13 | +} |
| 14 | + |
| 15 | +Describe 'MAUI app' -ForEach @( |
| 16 | + @{ tfm = "net9.0-android35.0" } |
| 17 | +) -Skip:(-not $script:emulator) { |
| 18 | + BeforeAll { |
| 19 | + Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue |
| 20 | + Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force |
| 21 | + Push-Location $PSScriptRoot/mobile-app |
| 22 | + |
| 23 | + function InstallAndroidApp |
| 24 | + { |
| 25 | + param([string] $Dsn) |
| 26 | + $dsn = $Dsn.Replace('http://', 'http://key@') + '/0' |
| 27 | + |
| 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 |
| 44 | + |
| 45 | + Write-Host "::group::Install bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk" |
| 46 | + xharness android install -v ` |
| 47 | + --app bin/Release/$tfm/$rid/io.sentry.dotnet.maui.device.integrationtestapp-Signed.apk ` |
| 48 | + --package-name io.sentry.dotnet.maui.device.integrationtestapp ` |
| 49 | + --output-directory=test_output |
| 50 | + | ForEach-Object { Write-Host $_ } |
| 51 | + Write-Host '::endgroup::' |
| 52 | + $LASTEXITCODE | Should -Be 0 |
| 53 | + } |
| 54 | + |
| 55 | + function RunAndroidApp |
| 56 | + { |
| 57 | + param( |
| 58 | + [string] $Dsn, |
| 59 | + [string] $TestArg = 'None' |
| 60 | + ) |
| 61 | + |
| 62 | + try |
| 63 | + { |
| 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 |
| 75 | + |
| 76 | + do |
| 77 | + { |
| 78 | + Write-Host "Waiting for app..." |
| 79 | + Start-Sleep -Seconds 1 |
| 80 | + |
| 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 | + } |
| 90 | + } |
| 91 | + |
| 92 | + function UninstallAndroidApp |
| 93 | + { |
| 94 | + Write-Host "::group::Uninstall io.sentry.dotnet.maui.device.integrationtestapp" |
| 95 | + xharness android uninstall -v ` |
| 96 | + --package-name io.sentry.dotnet.maui.device.integrationtestapp |
| 97 | + | ForEach-Object { Write-Host $_ } |
| 98 | + $LASTEXITCODE | Should -Be 0 |
| 99 | + Write-Host '::endgroup::' |
| 100 | + } |
| 101 | + |
| 102 | + # Helper to dump server stderr if the test server reported errors |
| 103 | + function Dump-ServerErrors { |
| 104 | + param( |
| 105 | + [Parameter(Mandatory)] |
| 106 | + $Result |
| 107 | + ) |
| 108 | + if ($Result.HasErrors()) { |
| 109 | + Write-Host '::group::sentry-server stderr' |
| 110 | + $Result.ServerStdErr | ForEach-Object { Write-Host $_ } |
| 111 | + Write-Host '::endgroup::' |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + AfterAll { |
| 117 | + Pop-Location |
| 118 | + } |
| 119 | + |
| 120 | + AfterEach { |
| 121 | + UninstallAndroidApp |
| 122 | + } |
| 123 | + |
| 124 | + It 'Managed crash' { |
| 125 | + $result = Invoke-SentryServer { |
| 126 | + param([string]$url) |
| 127 | + InstallAndroidApp -Dsn $url |
| 128 | + RunAndroidApp -Dsn $url -TestArg "Managed" |
| 129 | + RunAndroidApp -Dsn $url |
| 130 | + } |
| 131 | + |
| 132 | + Dump-ServerErrors -Result $result |
| 133 | + $result.HasErrors() | Should -BeFalse |
| 134 | + $result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`"" |
| 135 | + $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" |
| 136 | + } |
| 137 | + |
| 138 | + It 'Java crash' { |
| 139 | + $result = Invoke-SentryServer { |
| 140 | + param([string]$url) |
| 141 | + InstallAndroidApp -Dsn $url |
| 142 | + RunAndroidApp -Dsn $url -TestArg "Java" |
| 143 | + RunAndroidApp -Dsn $url |
| 144 | + } |
| 145 | + |
| 146 | + Dump-ServerErrors -Result $result |
| 147 | + $result.HasErrors() | Should -BeFalse |
| 148 | + $result.Envelopes() | Should -AnyElementMatch "`"type`":`"RuntimeException`"" |
| 149 | + $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`"" |
| 150 | + } |
| 151 | + |
| 152 | + It 'Null reference exception' { |
| 153 | + $result = Invoke-SentryServer { |
| 154 | + param([string]$url) |
| 155 | + InstallAndroidApp -Dsn $url |
| 156 | + RunAndroidApp -Dsn $url -TestArg "NullReferenceException" |
| 157 | + RunAndroidApp -Dsn $url |
| 158 | + } |
| 159 | + |
| 160 | + Dump-ServerErrors -Result $result |
| 161 | + $result.HasErrors() | Should -BeFalse |
| 162 | + $result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`"" |
| 163 | + # TODO: fix redundant RuntimeException (#3954) |
| 164 | + { $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGSEGV`"" } | Should -Throw |
| 165 | + } |
| 166 | +} |
0 commit comments