summaryrefslogtreecommitdiffhomepage
path: root/android/scripts
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2023-01-10 15:58:10 +0100
committerAlbin <albin@mullvad.net>2023-01-10 15:58:10 +0100
commit7ea38a3881b92b17658a5be4f0e627601212db6c (patch)
tree96c12212b3f95c7ea588099aec7cb5fdb22942ed /android/scripts
parentfee3b5804555b3287c9c59aecd3682f118735ba8 (diff)
parent57008a509342f547f5e56ef781a7f2e8a18298c0 (diff)
downloadmullvadvpn-7ea38a3881b92b17658a5be4f0e627601212db6c.tar.xz
mullvadvpn-7ea38a3881b92b17658a5be4f0e627601212db6c.zip
Merge branch 'add-instrumented-tests-using-mocked-api'
Diffstat (limited to 'android/scripts')
-rwxr-xr-xandroid/scripts/run-instrumented-tests.sh118
-rwxr-xr-xandroid/scripts/update-lockfile.sh2
2 files changed, 119 insertions, 1 deletions
diff --git a/android/scripts/run-instrumented-tests.sh b/android/scripts/run-instrumented-tests.sh
new file mode 100755
index 0000000000..27eb8a9be8
--- /dev/null
+++ b/android/scripts/run-instrumented-tests.sh
@@ -0,0 +1,118 @@
+#!/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"
+ ;;
+ mockapi)
+ TEST_TYPE="mockapi"
+ 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"
+ ;;
+ *)
+ 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, mockapi"
+ exit 1
+fi
+
+if [[ "${USE_ORCHESTRATOR-}" == "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/android/scripts/update-lockfile.sh b/android/scripts/update-lockfile.sh
index c30e3ca77c..9cbf81c92c 100755
--- a/android/scripts/update-lockfile.sh
+++ b/android/scripts/update-lockfile.sh
@@ -16,4 +16,4 @@ android_container_image_name=$(cat "../../building/android-container-image.txt")
podman run --rm -it \
-v ../..:/build:Z \
"$android_container_image_name" \
- android/gradlew -q -p android -M sha256 assembleAndroidTest
+ android/gradlew -q -p android -M sha256 assemble assembleAndroidTest