Files
Kordant/android/firebase-test-lab/run_all_tests.sh

248 lines
7.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# Run All Firebase Test Lab Tests
# =============================================================================
# Orchestrates the full Firebase Test Lab test suite:
# 1. Robo exploratory tests (crash detection without test code)
# 2. Instrumentation tests (UI tests with assertions)
#
# This script builds the app, runs both test types sequentially, and
# reports results.
#
# Prerequisites:
# 1. gcloud CLI installed and authenticated
# 2. Firebase project with Blaze plan enabled
# 3. Service account with Firebase Test Lab admin role
# 4. Java 17+ for Android builds
#
# Usage:
# ./run_all_tests.sh [options]
#
# Options:
# --project-id Firebase project ID (default: kordant-android)
# --skip-build Skip the Gradle build step
# --skip-robo Skip Robo tests (run instrumentation only)
# --skip-instr Skip instrumentation tests (run Robo only)
# --dry-run Print commands without executing
# --help Show this help message
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Default values
PROJECT_ID="${FIREBASE_PROJECT_ID:-kordant-android}"
SKIP_BUILD=false
SKIP_ROBO=false
SKIP_INSTR=false
DRY_RUN=false
# ============================================================
# Parse arguments
# ============================================================
while [[ $# -gt 0 ]]; do
case "$1" in
--project-id)
PROJECT_ID="$2"
shift 2
;;
--skip-build)
SKIP_BUILD=true
shift
;;
--skip-robo)
SKIP_ROBO=true
shift
;;
--skip-instr)
SKIP_INSTR=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
--help)
grep "^#" "$0" | grep -v "^#!/" | sed 's/^# //'
exit 0
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 --help"
exit 1
;;
esac
done
# ============================================================
# Timestamp helper
# ============================================================
timestamp() {
date "+%Y-%m-%d %H:%M:%S"
}
# ============================================================
# Validate prerequisites
# ============================================================
echo "=========================================="
echo "Firebase Test Lab - Full Test Suite"
echo "=========================================="
echo "Started at: $(timestamp)"
echo "Project ID: $PROJECT_ID"
echo ""
# Check gcloud
if ! command -v gcloud &> /dev/null; then
echo "Error: gcloud CLI is not installed."
echo "Install it from: https://cloud.google.com/sdk/docs/install"
exit 1
fi
# Check authentication
if ! gcloud auth application-default print-access-token &> /dev/null; then
echo "Warning: Application default credentials not set."
echo "Run: gcloud auth application-default login"
echo ""
# Check if user is authenticated at all
if ! gcloud auth list --filter=status:ACTIVE --format="value(account)" &> /dev/null; then
echo "Error: No active gcloud account. Run: gcloud auth login"
exit 1
fi
fi
# ============================================================
# Step 1: Build the app (if not skipped)
# ============================================================
if [ "$SKIP_BUILD" = false ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Step 1: Building Android APKs"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
cd "$PROJECT_DIR/android"
# Determine Java version
JAVA_VERSION=$(java -version 2>&1 | head -1 | grep -oP 'version "\K[^"]+' || echo "unknown")
echo "Java version: $JAVA_VERSION"
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would run: ./gradlew :app:assembleProdRelease :app:assembleProdDebugAndroidTest"
else
echo "Building release APK and test APK..."
./gradlew :app:assembleProdRelease :app:assembleProdDebugAndroidTest
echo ""
echo "Build completed. APK locations:"
find "$PROJECT_DIR/android/app/build/outputs" -name "*.apk" -type f 2>/dev/null | while read -r apk; do
size=$(stat -f%z "$apk" 2>/dev/null || stat -c%s "$apk" 2>/dev/null || echo "?")
echo " $(basename "$apk") ($(echo "scale=1; $size/1048576" | bc) MB)"
done
fi
echo ""
else
echo "⏭️ Build step skipped."
echo ""
fi
# ============================================================
# Step 2: Run Robo tests
# ============================================================
ROBO_RESULT=0
if [ "$SKIP_ROBO" = false ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🤖 Step 2: Running Robo Tests"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
ROBO_SCRIPT="${SCRIPT_DIR}/run_robo_tests.sh"
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would run: $ROBO_SCRIPT --project-id $PROJECT_ID"
else
if [ -f "$ROBO_SCRIPT" ]; then
bash "$ROBO_SCRIPT" --project-id "$PROJECT_ID" || ROBO_RESULT=$?
else
echo "Warning: $ROBO_SCRIPT not found, skipping Robo tests."
ROBO_RESULT=0
fi
fi
echo ""
else
echo "⏭️ Robo tests skipped."
echo ""
fi
# ============================================================
# Step 3: Run instrumentation tests
# ============================================================
INSTR_RESULT=0
if [ "$SKIP_INSTR" = false ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧪 Step 3: Running Instrumentation Tests"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
INSTR_SCRIPT="${SCRIPT_DIR}/run_instrumentation_tests.sh"
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would run: $INSTR_SCRIPT --project-id $PROJECT_ID"
else
if [ -f "$INSTR_SCRIPT" ]; then
bash "$INSTR_SCRIPT" --project-id "$PROJECT_ID" || INSTR_RESULT=$?
else
echo "Warning: $INSTR_SCRIPT not found, skipping instrumentation tests."
INSTR_RESULT=0
fi
fi
echo ""
else
echo "⏭️ Instrumentation tests skipped."
echo ""
fi
# ============================================================
# Step 4: Summary
# ============================================================
echo "=========================================="
echo "📊 Test Suite Summary"
echo "=========================================="
echo "Finished at: $(timestamp)"
echo ""
if [ "$SKIP_ROBO" = false ]; then
if [ $ROBO_RESULT -eq 0 ]; then
echo "✅ Robo Tests: PASSED"
else
echo "❌ Robo Tests: FAILED (exit code $ROBO_RESULT)"
fi
fi
if [ "$SKIP_INSTR" = false ]; then
if [ $INSTR_RESULT -eq 0 ]; then
echo "✅ Instrumentation: PASSED"
else
echo "❌ Instrumentation: FAILED (exit code $INSTR_RESULT)"
fi
fi
echo ""
echo "View all results in Firebase Console:"
echo " https://console.firebase.google.com/project/$PROJECT_ID/testlab"
echo ""
# Determine overall exit code
if [ "$SKIP_ROBO" = false ] && [ $ROBO_RESULT -ne 0 ]; then
exit $ROBO_RESULT
fi
if [ "$SKIP_INSTR" = false ] && [ $INSTR_RESULT -ne 0 ]; then
exit $INSTR_RESULT
fi
exit 0