Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
androidtestrunner.qdoc
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page android-test-runner.html
6 \brief Overview of the androidtestrunner tool for running Qt tests on Android.
7 \title The androidtestrunner Tool
8
9 \target androidtestrunner
10
11 \ingroup android-platform-extra-topics
12
13 \section1 Introduction
14
15 The \c androidtestrunner tool runs Qt tests on Android devices and emulators.
16 It automates the steps required to execute tests, including managing APK
17 installation, test execution, and retrieving results.
18
19 Before using the \c androidtestrunner, ensure you have configured your Qt
20 test project with CMake or qmake.
21
22 \section1 How it works
23
24 \list 1
25 \li Firstly, it begins by executing the APK build command to generate
26 the required APK for the test.
27 \li Following this, it installs the test app on the target device and
28 starts the test app, setting the testing process in motion.
29 \li The test results are written to the app’s data directory on the
30 device, ensuring that comprehensive test outputs are captured.
31 \li Once the tests conclude, the runner writes an exit code file beside
32 the result files.
33 \li At this stage, the \c androidtestrunner retrieves these result files
34 from the device, examining the exit code for failures.
35 \li If issues are detected, it immediately prints the app’s logcat logs,
36 including any potential crash stack traces, which are beautified to
37 reveal file names and line numbers for each frame. Additionally, it
38 captures and reports Application Not Responding (ANR) logs if such
39 events occur during the test execution.
40 \endlist
41
42 To enhance the integration experience, the test runner
43 propagates QT or QTEST environment variables from the host environment of
44 the test runner process to the app, ensuring consistency and a seamless
45 testing workflow.
46
47 \section1 Running tests with the test wrapper
48
49 Qt generates a per-target wrapper script alongside each Android test (named
50 after the test target) that invokes \c androidtestrunner with the right
51 paths and forwards any extra arguments to the test binary. The example below
52 runs \c tst_android on a specific emulator, forwards a Qt environment
53 variable, and executes only the \c testAssets test case:
54
55 \badcode
56 ANDROID_SERIAL=emulator-5554 QT_DEBUG_PLUGINS=1 ./tst_android testAssets
57 \endcode
58
59 \section1 Retrieving results
60
61 By default, and if the stdout test output is not explicitly disabled, the test
62 results are printed to the host as the test is executing. After running the
63 tests, any explicitly requested test files are pulled into the specified output
64 path with their respective formats.
65
66 For comprehensive details about Qt Test Framework, see \l {Qt Test Overview}.
67
68 \section1 How to use it
69
70 The basic syntax to run the \c androidtestrunner is as follows:
71
72 \badcode
73 androidtestrunner [ARGUMENTS] -- [TESTARGS]
74 \endcode
75
76 To run the test on a specific device/emulator, pass \c {--serial <serial>}
77 or set the \c adb environment variable \c ANDROID_SERIAL or
78 \c ANDROID_DEVICE_SERIAL. The explicit option takes precedence.
79
80 \section2 Mandatory Arguments
81
82 The test runner always expects the following arguments to be passed:
83
84 \list
85 \li \c {--path <build-path>}: The path where the Android Gradle
86 package is built, typically \c {<build-dir>/android-build-<target>}.
87 \li \c {--make <build-command>}: The command used to build the test APK,
88 for example, \c {cmake --build <build-dir> --target <target>_make_apk}.
89 \note Pass this argument quoted so it's not treated as multiple arguments
90 of the test runner but as the value of \c {--make} argument.
91 \li One of:
92 \list
93 \li \c {--apk <apk-path>}: Path to the test APK generated by the
94 build command and installed on the device.
95 \li \c {--aab <aab-path>}: Path to the test AAB; requires
96 \c {--bundletool}. Both options cannot be set at the same
97 time, and neither may be specified more than once.
98 \endlist
99 \endlist
100
101 \section2 Optional arguments
102
103 You can also pass the following optional arguments:
104
105 \list
106 \li \c {--bundletool <path>}: Path to the Android \c bundletool jar.
107 Required when \c {--aab} is used.
108 \li \c {--manifest <path>}: Custom \c AndroidManifest.xml path. Defaults
109 to a file discovered under the build path or its \c app/
110 subdirectory.
111 \li \c {--adb <adb-path>}: Specifies a custom ADB command path.
112 Defaults to the \c adb path found in the system's \c $PATH.
113 \li \c {--serial <serial>}: Android device serial to target. Overrides
114 \c ANDROID_SERIAL and \c ANDROID_DEVICE_SERIAL.
115 \li \c {--activity <activity-name>}: Specifies a custom activity to run.
116 Defaults to the first activity defined in the \c AndroidManifest.xml.
117 \li \c {--timeout <seconds>}: Sets the timeout for running the test.
118 Defaults to 600 seconds (10 minutes).
119 \li \c {--pre-test-adb-command <command>}: Call the adb \c {<command>}
120 after installation and before the test run. Can be passed
121 multiple times.
122 \li \c --skip-install-root: Suppresses the automatic
123 \c {INSTALL_ROOT=<path> install} suffix that is appended to
124 \c --make when the build command is a \c make-family tool
125 (\c make, \c gmake, \c nmake, \c mingw32-make, \c jom; matched
126 case-insensitively). The suffix is never appended for \c cmake,
127 \c ninja or other build drivers, so this option only has an
128 effect with the listed tools.
129 \li \c {--ndk-stack <command-path>}: Specifies the path to the
130 \l {Android: ndk-stack}{ndk-stack} tool for symbolizing crash stack
131 traces. Defaults to the tool path found under \c $ANDROID_NDK_ROOT.
132 \li \c --show-logcat: Prints the logcat output to stdout regardless
133 of test failure. Reads the main, system and crash buffers, and
134 includes \c system_server lines when an ANR is detected.
135 \li \c --verbose: Prints verbose output.
136 \li \c {-- <arguments>}: Passes anything after the dashes as test arguments.
137 \li \c --help: Displays the help information.
138 \endlist
139
140 \section2 Example usage
141
142 Here is an example that runs the \c tst_android test, executing only
143 \c testAssets test case:
144
145 \badcode
146 androidtestrunner \
147 --path ~/tst_android/build/android-build-tst_openssl \
148 --make "cmake --build ~/tst_android/build --target apk" \
149 --apk ~/tst_android/build/android-build-tst_openssl/tst_openssl.apk \
150 testAssets
151 \endcode
152*/