summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/android-app.yml3
-rwxr-xr-xandroid/scripts/run-instrumented-tests.sh112
-rwxr-xr-xci/run-android-instrumented-tests.sh31
3 files changed, 114 insertions, 32 deletions
diff --git a/.github/workflows/android-app.yml b/.github/workflows/android-app.yml
index 0a07e163b2..64a08f4380 100644
--- a/.github/workflows/android-app.yml
+++ b/.github/workflows/android-app.yml
@@ -147,6 +147,7 @@ jobs:
- uses: actions/download-artifact@v3
with:
name: apks
+ path: android/app/build/outputs/apk
- name: AVD cache
uses: actions/cache@v3
@@ -182,6 +183,6 @@ jobs:
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
profile: pixel
- script: ./ci/run-android-instrumented-tests.sh $(pwd)
+ script: ./android/scripts/run-instrumented-tests.sh app
env:
API_LEVEL: 33
diff --git a/android/scripts/run-instrumented-tests.sh b/android/scripts/run-instrumented-tests.sh
new file mode 100755
index 0000000000..3763324c15
--- /dev/null
+++ b/android/scripts/run-instrumented-tests.sh
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+
+set -eu
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "$SCRIPT_DIR"
+
+APK_BASE_DIR=${APK_BASE_DIR:-"$SCRIPT_DIR/.."}
+LOG_FAILURE_MESSAGE="FAILURES!!!"
+
+while [[ "$#" -gt 0 ]]; do
+ case $1 in
+ app)
+ TEST_TYPE="app"
+ USE_ORCHESTRATOR="false"
+ TEST_PACKAGE="net.mullvad.mullvadvpn.test"
+ TEST_APK="$APK_BASE_DIR/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk"
+ ;;
+ e2e)
+ TEST_TYPE="e2e"
+ USE_ORCHESTRATOR="true"
+ TEST_PACKAGE="net.mullvad.mullvadvpn.test.$TEST_TYPE"
+ TEST_APK="$APK_BASE_DIR/test/$TEST_TYPE/build/outputs/apk/debug/$TEST_TYPE-debug.apk"
+ if [[ -z ${VALID_TEST_ACCOUNT_TOKEN-} ]]; then
+ echo "The variable VALID_TEST_ACCOUNT_TOKEN is not set."
+ exit 1
+ fi
+ if [[ -z ${INVALID_TEST_ACCOUNT_TOKEN-} ]]; then
+ echo "The variable INVALID_TEST_ACCOUNT_TOKEN is not set."
+ exit 1
+ fi
+ OPTIONAL_TEST_ARGUMENTS="\
+ -e valid_test_account_token $VALID_TEST_ACCOUNT_TOKEN \
+ -e invalid_test_account_token $INVALID_TEST_ACCOUNT_TOKEN"
+ ;;
+ *)
+ echo "Unknown argument: $1"
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+if [[ -z ${TEST_TYPE-} ]]; then
+ echo "Missing test type argument. Should be one of: app, e2e"
+ exit 1
+fi
+
+if [[ "${ORCHESTRATOR_APK_PATH-}" == "true" ]]; then
+ if [[ -z ${ORCHESTRATOR_APK_PATH-} ]]; then
+ echo "The variable ORCHESTRATOR_APK_PATH is not set."
+ exit 1
+ fi
+ if [[ -z ${TEST_SERVICES_APK_PATH-} ]]; then
+ echo "The variable TEST_SERVICES_APK_PATH is not set."
+ exit 1
+ fi
+fi
+
+LOG_FILE_NAME="mullvad-$TEST_TYPE.txt"
+LOG_FILE_PATH="/tmp/$LOG_FILE_NAME"
+
+echo "Starting instrumented tests of type: $TEST_TYPE"
+echo ""
+
+echo "### Ensure that packages are not previously installed ###"
+adb uninstall net.mullvad.mullvadvpn || echo "App package not installed"
+adb uninstall "$TEST_PACKAGE" || echo "Test package not installed"
+adb uninstall androidx.test.services || echo "Test services package not installed"
+adb uninstall androidx.test.orchestrator || echo "Test orchestrator package not installed"
+echo ""
+
+echo "### Install packages ###"
+adb install -t "$APK_BASE_DIR/app/build/outputs/apk/debug/app-debug.apk"
+adb install "$TEST_APK"
+if [[ "$USE_ORCHESTRATOR" == "true" ]]; then
+ adb install "$ORCHESTRATOR_APK_PATH"
+ adb install "$TEST_SERVICES_APK_PATH"
+fi
+echo ""
+
+echo "### Run instrumented test command ###"
+if [[ "$USE_ORCHESTRATOR" == "true" ]]; then
+ INSTRUMENTATION_COMMAND="\
+ CLASSPATH=\$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain \
+ am instrument -r -w \
+ -e targetInstrumentation $TEST_PACKAGE/androidx.test.runner.AndroidJUnitRunner \
+ -e clearPackageData true \
+ ${OPTIONAL_TEST_ARGUMENTS:-""} \
+ androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestOrchestrator"
+else
+ INSTRUMENTATION_COMMAND="\
+ am instrument -w \
+ $TEST_PACKAGE/androidx.test.runner.AndroidJUnitRunner"
+fi
+adb shell "$INSTRUMENTATION_COMMAND" | tee "$LOG_FILE_PATH"
+echo ""
+
+echo "### Ensure that packages are uninstalled ###"
+adb uninstall net.mullvad.mullvadvpn || echo "App package not installed"
+adb uninstall "$TEST_PACKAGE" || echo "Test package not installed"
+adb uninstall androidx.test.services || echo "Test services package not installed"
+adb uninstall androidx.test.orchestrator || echo "Test orchestrator package not installed"
+echo ""
+
+echo "### Checking logs for failures ###"
+if grep -q "$LOG_FAILURE_MESSAGE" "$LOG_FILE_PATH"; then
+ echo "One or more tests failed, see logs for more details."
+ exit 1
+else
+ echo "No failures!"
+fi
diff --git a/ci/run-android-instrumented-tests.sh b/ci/run-android-instrumented-tests.sh
deleted file mode 100755
index cf29289c3d..0000000000
--- a/ci/run-android-instrumented-tests.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env bash
-
-APK_BASE_DIR=$1
-LOG_FILE_NAME="mullvad.instrumentation_data_proto"
-LOG_FILE_PATH="/sdcard/$LOG_FILE_NAME"
-LOG_FAILURE_MESSAGE="FAILURES\!\!\!"
-
-echo "Running instrumented tests..."
-echo ""
-
-echo "### Ensure uninstalled ###"
-adb uninstall net.mullvad.mullvadvpn || echo "App package not installed"
-adb uninstall net.mullvad.mullvadvpn.test || echo "Test package not installed"
-echo ""
-
-echo "### Install ###"
-adb install -t "$APK_BASE_DIR/debug/app-debug.apk"
-adb install "$APK_BASE_DIR/androidTest/debug/app-debug-androidTest.apk"
-echo ""
-
-echo "### Start tests ###"
-adb shell am instrument -w -f "$LOG_FILE_NAME" net.mullvad.mullvadvpn.test/androidx.test.runner.AndroidJUnitRunner
-echo ""
-
-# Print log so that it shows as part of GitHub Actions logs etc
-echo "### Logs ###"
-adb shell cat "$LOG_FILE_PATH"
-
-if adb shell grep -q "$LOG_FAILURE_MESSAGE" "$LOG_FILE_PATH"; then
- exit 1
-fi