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 \ingroup android-platform-extra-topics
10
11 \section1 Introduction
12
13 The \c androidtestrunner tool runs Qt tests on Android devices and emulators.
14 It automates the steps required to execute tests, including managing APK
15 installation, test execution, and retrieving results.
16
17 Before using the \c androidtestrunner, ensure you have configured your Qt
18 test project with CMake or qmake.
19
20 \section1 How it works
21
22 \list 1
23 \li Firstly, it begins by executing the APK build command to generate
24 the required APK for the test.
25 \li Following this, it installs the test app on the target device and
26 starts the test app, setting the testing process in motion.
27 \li The test results are written to the app’s data directory on the
28 device, ensuring that comprehensive test outputs are captured.
29 \li Once the tests conclude, the runner writes an exit code file beside
30 the result files.
31 \li At this stage, the \c androidtestrunner retrieves these result files
32 from the device, examining the exit code for failures.
33 \li If issues are detected, it immediately prints the app’s logcat logs,
34 including any potential crash stack traces, which are beautified to
35 reveal file names and line numbers for each frame. Additionally, it
36 captures and reports Application Not Responding (ANR) logs if such
37 events occur during the test execution.
38 \endlist
39
40 To enhance the integration experience, the test runner
41 propagates QT or QTEST environment variables from the host environment of
42 the test runner process to the app, ensuring consistency and a seamless
43 testing workflow.
44
45 \section1 Running tests with the test wrapper
46
47 Here is an example that runs the \c tst_android test while running it on
48 a specific emulator instance, passing an environment variable and executing
49 only \c testAssets test case:
50
51 \badcode
52 ANDROID_SERIAL=emulator-5554 QT_DEBUG_PLUGINS=1 ./tst_android testAssets
53 \endcode
54
55 \section1 Retrieving results
56
57 By default, and if the stdout test output is not explicitly disabled, the test
58 results are printed to the host as the test is executing. After running the
59 tests, any explicitly requested test files are pulled into the specified output
60 path with their respective formats.
61
62 For comprehensive details about Qt Test Framework, see \l {Qt Test Overview}.
63
64 \section1 How to use it
65
66 The basic syntax to run the \c androidtestrunner is as follows:
67
68 \badcode
69 androidtestrunner [ARGUMENTS] -- [TESTARGS]
70 \endcode
71
72 To run the test on a specific device/emulator, use the \c adb environment
73 varialbe \c ANDROID_SERIAL or \c ANDROID_DEVICE_SERIAL.
74
75 \section2 Mandatory Arguments
76
77 The test runner always expects the following arguments to be passed:
78
79 \list
80 \li \c {--path <build-path>}: The path where the Android Gradle package
81 is built, commonly under \c {android-build-testname}.
82 \li \c {--make <build-command>}: The command used to build the test APK,
83 for example, \c {cmake --build <build-dir> --target <target>_make_apk}.
84 \note Pass this argument quoted so it's not treated as multiple arguments
85 of the test runner but as the value of \c {--make} argument.
86 \li \c {--apk <apk-path>}: The Path to the test APK that is generated by
87 the build command and that is installed on the device.
88 \endlist
89
90 \section2 Optional arguments
91
92 You can also pass the following optional arguments:
93
94 \list
95 \li \c {--adb <adb-path>}: Specifies a custom ADB command path.
96 Defaults to the \c adb path found in the system's \c $PATH.
97 \li \c {--activity <activity-name>}: Specifies a custom activity to run.
98 Defaults to the first activity defined in the \c AndroidManifest.xml.
99 \li \c {--timeout <seconds>}: Sets the timeout for running the test.
100 Defaults to 600 seconds (10 minutes).
101 \li \c --skip-install-root: Avoids appending INSTALL_ROOT to the make
102 command and is mainly useful when using \c qmake.
103 \li \c --show-logcat: Prints the logcat output to stdout regardless of
104 test failure. Logs are printed in case of failure and can include
105 crash stacktraces or ANR events.
106 \li \c {--ndk-stack <command-path>}: Specifies the path to the
107 \l {Android: ndk-stack}{ndk-stack} tool for symbolizing crash stack
108 traces. Defaults to the tool path found under \c $ANDROID_NDK_ROOT.
109 \li \c {--pre-test-adb-command <command>}: call the adb <command> after
110 installation and before the test run.
111 \li \c {-- <arguments>}: Passes anything after the dashes as test arguments.
112 \li \c --verbose: Prints verbose output.
113 \li \c --help: Displays the help information.
114 \endlist
115
116 \section2 Example usage
117
118 Here is an example that runs the \c tst_android test, executing only
119 \c testAssets test case:
120
121 \badcode
122 androidtestrunner \
123 --path ~/tst_android/build/android-build-tst_openssl \
124 --make "cmake --build ~/tst_android/build --target apk" \
125 --apk ~/tst_android/build/android-build-tst_openssl/tst_openssl.apk \
126 --skip-install-root \
127 testAssets
128 \endcode
129*/