22# Supports both ADB (local devices/emulators) and SauceLabs (cloud devices)
33#
44# Usage:
5- # # Default (uses ADB)
65# Invoke-Pester Integration.Android.Tests.ps1
76#
8- # # Explicit platform selection with Pester containers
9- # $Container = New-PesterContainer -Path 'Integration.Android.Tests.ps1' -Data @{ Platform = 'Adb' }
10- # Invoke-Pester -Container $Container
11- #
12- # $Container = New-PesterContainer -Path 'Integration.Android.Tests.ps1' -Data @{ Platform = 'SauceLabs' }
13- # Invoke-Pester -Container $Container
14- #
157# Requires:
168# - Pre-built APK
179# - Environment variables: SENTRY_UNREAL_TEST_DSN, SENTRY_AUTH_TOKEN, SENTRY_UNREAL_TEST_APP_PATH
2012# - Android emulator or device connected via ADB
2113#
2214# For SauceLabs:
23- # - SAUCE_USERNAME, SAUCE_ACCESS_KEY, SAUCE_REGION, SAUCE_DEVICE_NAME
24-
25- param (
26- [Parameter (Mandatory = $false )]
27- [ValidateSet (' Adb' , ' SauceLabs' )]
28- [string ]$Platform = ' Adb'
29- )
15+ # - SAUCE_USERNAME, SAUCE_ACCESS_KEY, SAUCE_REGION, SAUCE_DEVICE_NAME, SAUCE_SESSION_NAME
3016
3117Set-StrictMode - Version Latest
3218$ErrorActionPreference = ' Stop'
3319
34- BeforeAll {
35- # Map friendly platform name to app-runner platform name
36- $appRunnerPlatform = if ($Platform -eq ' Adb' ) { ' AndroidAdb' } else { ' AndroidSauceLabs' }
20+ BeforeDiscovery {
21+ # Define test targets
22+ function Get-TestTarget {
23+ param (
24+ [string ]$Platform ,
25+ [string ]$ProviderName
26+ )
27+
28+ return @ {
29+ Platform = $Platform
30+ ProviderName = $ProviderName
31+ }
32+ }
33+
34+ $TestTargets = @ ()
35+
36+ # Detect if running in CI environment
37+ # In CI, running tests using SauceLabs is mandatory while adb tests are skipped due to emulator limitations
38+ $isCI = $env: CI -eq ' true'
39+
40+ # Check adb test configuration
41+ if (Get-Command ' adb' - ErrorAction SilentlyContinue) {
42+ # Check if any devices are connected
43+ $adbDevices = adb devices
44+ if ($adbDevices -match ' \tdevice$' ) {
45+ $TestTargets += Get-TestTarget - Platform ' Adb' - ProviderName ' Adb'
46+ }
47+ else {
48+ Write-Host " No devices connected via adb. Adb tests will be skipped."
49+ }
50+ }
51+ else {
52+ Write-Host " adb not found in PATH. Adb tests will be skipped."
53+ }
54+
55+ # Check SauceLabs test configuration
56+ if ($env: SAUCE_USERNAME -and $env: SAUCE_ACCESS_KEY -and $env: SAUCE_REGION -and $env: SAUCE_DEVICE_NAME -and $env: SAUCE_SESSION_NAME ) {
57+ $TestTargets += Get-TestTarget - Platform ' SauceLabs' - ProviderName ' AndroidSauceLabs'
58+ }
59+ else {
60+ $message = " SauceLabs credentials not found"
61+ if ($isCI ) {
62+ throw " $message . These are required in CI."
63+ }
64+ else {
65+ Write-Host " $message . SauceLabs tests will be skipped."
66+ }
67+ }
3768
38- Write-Host " Running Android tests with platform: $Platform (app-runner: $appRunnerPlatform )" - ForegroundColor Cyan
69+ # Inform user if no test targets are available
70+ if ($TestTargets.Count -eq 0 ) {
71+ Write-Warning " No Android test targets detected. Integration tests will be skipped."
72+ Write-Warning " To run Android integration tests, configure at least one test target:"
73+ Write-Warning " - Adb: ADB must be in PATH and at least one Android device must be connected (physical or emulator)"
74+ Write-Warning " - SauceLabs: Environment variables SAUCE_USERNAME, SAUCE_ACCESS_KEY, SAUCE_REGION, SAUCE_DEVICE_NAME, SAUCE_SESSION_NAME must be set"
75+ }
76+ }
3977
78+ BeforeAll {
4079 # Check if configuration file exists
4180 $configFile = " $PSScriptRoot /TestConfig.local.ps1"
4281 if (-not (Test-Path $configFile )) {
@@ -83,39 +122,49 @@ BeforeAll {
83122
84123 $script :PackageName = " io.sentry.unreal.sample"
85124 $script :ActivityName = " $script :PackageName /com.epicgames.unreal.GameActivity"
125+ }
86126
87- # Connect to Android device (provider validates its own env vars)
88- Write-Host " Connecting to Android via $Platform ..." - ForegroundColor Yellow
89- Connect-Device - Platform $appRunnerPlatform
127+ Describe ' Sentry Unreal Android Integration Tests (<Platform>)' - ForEach $TestTargets {
90128
91- # Install APK
92- Write-Host " Installing APK via $Platform ..." - ForegroundColor Yellow
93- Install-DeviceApp - Path $script :ApkPath
129+ BeforeAll {
130+ # Connect to Android device (provider validates its own env vars)
131+ Write-Host " Connecting to Android via $Platform ..." - ForegroundColor Yellow
132+ Connect-Device - Platform $ProviderName
94133
95- # ==========================================
96- # RUN 1: Crash test - creates minidump
97- # ==========================================
98- # The crash is captured but NOT uploaded yet (Android behavior).
134+ # Install APK
135+ Write-Host " Installing APK via $Platform ..." - ForegroundColor Yellow
136+ Install-DeviceApp - Path $script :ApkPath
99137
100- Write-Host " Running crash-capture test (will crash)..." - ForegroundColor Yellow
101- $cmdlineCrashArgs = " -e cmdline -crash-capture"
102- $global :AndroidCrashResult = Invoke-DeviceApp - ExecutablePath $script :ActivityName - Arguments $cmdlineCrashArgs
138+ # ==========================================
139+ # RUN 1: Crash test - creates minidump
140+ # ==========================================
141+ # The crash is captured but NOT uploaded yet (Android behavior).
103142
104- Write-Host " Crash test exit code: $ ( $global :AndroidCrashResult.ExitCode ) " - ForegroundColor Cyan
143+ Write-Host " Running crash-capture test (will crash) on $Platform ..." - ForegroundColor Yellow
144+ $cmdlineCrashArgs = " -e cmdline -crash-capture"
145+ $global :AndroidCrashResult = Invoke-DeviceApp - ExecutablePath $script :ActivityName - Arguments $cmdlineCrashArgs
105146
106- # ==========================================
107- # RUN 2: Message test - uploads crash from Run 1 + captures message
108- # ==========================================
109- # Currently we need to run again so that Sentry sends the crash event captured during the previous app session.
147+ Write-Host " Crash test exit code: $ ( $global :AndroidCrashResult.ExitCode ) " - ForegroundColor Cyan
110148
111- Write-Host " Running message-capture test on $Platform ..." - ForegroundColor Yellow
112- $cmdlineMessageArgs = " -e cmdline -message-capture"
113- $global :AndroidMessageResult = Invoke-DeviceApp - ExecutablePath $script :ActivityName - Arguments $cmdlineMessageArgs
149+ # ==========================================
150+ # RUN 2: Message test - uploads crash from Run 1 + captures message
151+ # ==========================================
152+ # Currently we need to run again so that Sentry sends the crash event captured during the previous app session.
114153
115- Write-Host " Message test exit code: $ ( $global :AndroidMessageResult.ExitCode ) " - ForegroundColor Cyan
116- }
154+ Write-Host " Running message-capture test on $Platform ..." - ForegroundColor Yellow
155+ $cmdlineMessageArgs = " -e cmdline -message-capture"
156+ $global :AndroidMessageResult = Invoke-DeviceApp - ExecutablePath $script :ActivityName - Arguments $cmdlineMessageArgs
157+
158+ Write-Host " Message test exit code: $ ( $global :AndroidMessageResult.ExitCode ) " - ForegroundColor Cyan
159+ }
160+
161+ AfterAll {
162+ # Disconnect from Android device
163+ Write-Host " Disconnecting from $Platform ..." - ForegroundColor Yellow
164+ Disconnect-Device
117165
118- Describe " Sentry Unreal Android Integration Tests ($Platform )" {
166+ Write-Host " Integration tests complete on $Platform " - ForegroundColor Green
167+ }
119168
120169 Context " Crash Capture Tests" {
121170 BeforeAll {
@@ -135,10 +184,12 @@ Describe "Sentry Unreal Android Integration Tests ($Platform)" {
135184 try {
136185 $CrashEvent = Get-SentryTestEvent - TagName ' test.crash_id' - TagValue " $crashId "
137186 Write-Host " Crash event fetched from Sentry successfully" - ForegroundColor Green
138- } catch {
187+ }
188+ catch {
139189 Write-Host " Failed to fetch crash event from Sentry: $_ " - ForegroundColor Red
140190 }
141- } else {
191+ }
192+ else {
142193 Write-Host " Warning: No crash event ID found in output" - ForegroundColor Yellow
143194 }
144195 }
@@ -263,10 +314,6 @@ Describe "Sentry Unreal Android Integration Tests ($Platform)" {
263314}
264315
265316AfterAll {
266- # Disconnect from Android device
267- Write-Host " Disconnecting from $Platform ..." - ForegroundColor Yellow
268- Disconnect-Device
269-
270317 # Disconnect from Sentry API
271318 Write-Host " Disconnecting from Sentry API..." - ForegroundColor Yellow
272319 Disconnect-SentryApi
0 commit comments