Skip to content

Commit 046f867

Browse files
committed
Update Android test script
1 parent 8c75f1d commit 046f867

File tree

2 files changed

+102
-67
lines changed

2 files changed

+102
-67
lines changed

integration-test/Integration.Android.Tests.ps1

Lines changed: 96 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
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
@@ -20,23 +12,70 @@
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

3117
Set-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

265316
AfterAll {
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

integration-test/README.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,39 +107,27 @@ cd integration-test
107107
pwsh -Command "Invoke-Pester Integration.Tests.ps1"
108108
```
109109

110-
### Android (Local via ADB)
110+
### Android
111111

112112
```powershell
113-
# Ensure device/emulator is connected
114-
adb devices
115-
116113
# Set environment variables
117114
$env:SENTRY_UNREAL_TEST_DSN = "https://[email protected]/project"
118115
$env:SENTRY_AUTH_TOKEN = "sntrys_your_token_here"
119116
$env:SENTRY_UNREAL_TEST_APP_PATH = "./path/to/SentryPlayground.apk"
120117
121-
# Run tests (uses ADB by default)
122-
cd integration-test
123-
Invoke-Pester Integration.Android.Tests.ps1
124-
```
125-
126-
### Android (Cloud via SauceLabs)
118+
# Ensure device/emulator is connected (for ADB)
119+
adb devices
127120
128-
```powershell
129-
# Set environment variables
130-
$env:SENTRY_UNREAL_TEST_DSN = "https://[email protected]/project"
131-
$env:SENTRY_AUTH_TOKEN = "sntrys_your_token_here"
132-
$env:SENTRY_UNREAL_TEST_APP_PATH = "./path/to/SentryPlayground.apk"
121+
# Set credentials (for SauceLabs)
133122
$env:SAUCE_USERNAME = "your-saucelabs-username"
134123
$env:SAUCE_ACCESS_KEY = "your-saucelabs-access-key"
135124
$env:SAUCE_REGION = "us-west-1"
136125
$env:SAUCE_DEVICE_NAME = "Samsung_Galaxy_S23_15_real_sjc1"
137126
$env:SAUCE_SESSION_NAME = "My Custom Test Session" # Optional, defaults to "App Runner Android Test"
138127
139-
# Run tests with explicit platform selection
128+
# Run tests (uses ADB by default)
140129
cd integration-test
141-
$Container = New-PesterContainer -Path 'Integration.Android.Tests.ps1' -Data @{ Platform = 'SauceLabs' }
142-
Invoke-Pester -Container $Container
130+
Invoke-Pester Integration.Android.Tests.ps1
143131
```
144132

145133
**Note**: Ensure `SAUCE_DEVICE_NAME` matches a device available in your `SAUCE_REGION`. See the [SauceLabs Platform Configurator](https://app.saucelabs.com/live/web-testing) to find available devices for your region.

0 commit comments

Comments
 (0)