blob: 9e10a693d98882cf073cf52d91db2a39dcd55958 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:091# Android Test Instructions
2
andybons3322f762015-08-24 21:37:093[TOC]
4
jbudorick25c17382016-08-03 18:53:075## Device Setup
6
7### Physical Device Setup
8
9#### ADB Debugging
andybons3322f762015-08-24 21:37:0910
Andrew Grieveb747e712017-11-23 16:58:3111The adb executable exists within the Android SDK:
12
13```shell
14third_party/android_tools/sdk/platform-tools/adb
15```
16
andybons3322f762015-08-24 21:37:0917In order to allow the ADB to connect to the device, you must enable USB
18debugging:
andybons22afb312015-08-31 02:24:5119
20* Before Android 4.1 (Jelly Bean):
21 * Go to "System Settings"
22 * Go to "Developer options"
23 * Check "USB debugging".
24 * Un-check "Verify apps over USB".
ntfschr09699f442017-01-12 22:20:4625* On Jelly Bean and above, developer options are hidden by default. To unhide
26 them:
andybons22afb312015-08-31 02:24:5127 * Go to "About phone"
28 * Tap 10 times on "Build number"
29 * The "Developer options" menu will now be available.
30 * Check "USB debugging".
31 * Un-check "Verify apps over USB".
andybons3322f762015-08-24 21:37:0932
jbudorick25c17382016-08-03 18:53:0733#### Screen
andybons3322f762015-08-24 21:37:0934
ntfschr09699f442017-01-12 22:20:4635You **must** ensure that the screen stays on while testing: `adb shell svc power
36stayon usb` Or do this manually on the device: Settings -> Developer options ->
37Stay Awake.
andybons3322f762015-08-24 21:37:0938
39If this option is greyed out, stay awake is probably disabled by policy. In that
40case, get another device or log in with a normal, unmanaged account (because the
41tests will break in exciting ways if stay awake is off).
42
jbudorick25c17382016-08-03 18:53:0743#### Disable Verify Apps
andybons3322f762015-08-24 21:37:0944
ntfschr09699f442017-01-12 22:20:4645You may see a dialog like [this
46one](http://www.samsungmobileusa.com/simulators/ATT_GalaxyMega/mobile/screens/06-02_12.jpg),
andybons3322f762015-08-24 21:37:0947which states, _Google may regularly check installed apps for potentially harmful
48behavior._ This can interfere with the test runner. To disable this dialog, run:
ntfschr09699f442017-01-12 22:20:4649
50```
51adb shell settings put global package_verifier_enable 0
52```
andybons3322f762015-08-24 21:37:0953
Anthony Berent8d3ce022018-01-15 12:24:3654### Using Emulators
andybons3322f762015-08-24 21:37:0955
Andrew Grieveae094e392018-06-15 16:10:2256Running tests on emulators is the same as on device. Refer to
57[android_emulators.md](android_emulators.md) for setting up emulators.
andybons3322f762015-08-24 21:37:0958
59## Building Tests
60
jbudorick25c17382016-08-03 18:53:0761If you're adding a new test file, you'll need to explicitly add it to a gn
ntfschr09699f442017-01-12 22:20:4662target. If you're adding a test to an existing file, you won't need to make gn
jbudorick25c17382016-08-03 18:53:0763changes, but you may be interested in where your test winds up. In either case,
64here are some guidelines for where a test belongs:
andybons3322f762015-08-24 21:37:0965
jbudorick25c17382016-08-03 18:53:0766### C++
andybons3322f762015-08-24 21:37:0967
jbudorick25c17382016-08-03 18:53:0768C++ test files typically belong in `<top-level directory>_unittests` (e.g.
69`base_unittests` for `//base`). There are a few exceptions -- browser tests are
70typically their own target (e.g. `content_browsertests` for `//content`, or
71`browser_tests` for `//chrome`), and some unit test suites are broken at the
72second directory rather than the top-level one.
73
74### Java
75
76Java test files vary a bit more widely than their C++ counterparts:
77
ntfschr09699f442017-01-12 22:20:4678- Instrumentation test files -- i.e., tests that will run on a device --
79 typically belong in either `<top-level directory>_javatests` or `<top-level
80 directory>_test_java`. Regardless, they'll wind up getting packaged into one
81 of a few test APKs:
ctzsm34f54d62017-04-21 17:04:0782 - `webview_instrumentation_test_apk` for anything in `//android_webview`
ntfschr09699f442017-01-12 22:20:4683 - `content_shell_test_apk` for anything in `//content` or below
84 - `chrome_public_test_apk` for most things in `//chrome`
85 - `chrome_sync_shell_test_apk` in a few exceptional cases
86- JUnit or Robolectric test files -- i.e., tests that will run on the host --
87 typically belong in `<top-level directory>_junit_tests` (e.g.
88 `base_junit_tests` for `//base`), though here again there are cases
89 (particularly in `//components`) where suites are split at the second
90 directory rather than the top-level one.
andybons3322f762015-08-24 21:37:0991
92Once you know what to build, just do it like you normally would build anything
newt17e4d242015-08-27 09:07:2693else, e.g.: `ninja -C out/Release chrome_public_test_apk`
andybons3322f762015-08-24 21:37:0994
95## Running Tests
96
jbudorick25c17382016-08-03 18:53:0797All functional tests should be runnable via the wrapper scripts generated at
98build time:
99
100```sh
101<output directory>/bin/run_<target_name> [options]
102```
103
104Note that tests are sharded across all attached devices unless explicitly told
105to do otherwise by `-d/--device`.
andybons3322f762015-08-24 21:37:09106
107The commands used by the buildbots are printed in the logs. Look at
xiaoyin.l1003c0b2016-12-06 02:51:17108https://build.chromium.org/ to duplicate the same test command as a particular
andybons3322f762015-08-24 21:37:09109builder.
110
jbudorick25c17382016-08-03 18:53:07111### INSTALL\_FAILED\_CONTAINER\_ERROR or INSTALL\_FAILED\_INSUFFICIENT\_STORAGE
andybons3322f762015-08-24 21:37:09112
jbudorick25c17382016-08-03 18:53:07113If you see this error when the test runner is attempting to deploy the test
andybons3322f762015-08-24 21:37:09114binaries to the AVD emulator, you may need to resize your userdata partition
115with the following commands:
116
117```shell
davve7ae32cd2015-09-22 06:54:09118# Resize userdata partition to be 1G
mikecase7c263052017-03-30 23:46:11119resize2fs android_emulator_sdk/sdk/system-images/android-25/x86/userdata.img 1G
andybons3322f762015-08-24 21:37:09120
121# Set filesystem parameter to continue on errors; Android doesn't like some
122# things e2fsprogs does.
mikecase7c263052017-03-30 23:46:11123tune2fs -e continue android_emulator_sdk/sdk/system-images/android-25/x86/userdata.img
andybons3322f762015-08-24 21:37:09124```
125
126## Symbolizing Crashes
127
ntfschr09699f442017-01-12 22:20:46128Crash stacks are logged and can be viewed using `adb logcat`. To symbolize the
jyasskinc1c76ff2015-12-18 21:39:52129traces, define `CHROMIUM_OUTPUT_DIR=$OUTDIR` where `$OUTDIR` is the argument you
130pass to `ninja -C`, and pipe the output through
131`third_party/android_platform/development/scripts/stack`. If
132`$CHROMIUM_OUTPUT_DIR` is unset, the script will search `out/Debug` and
133`out/Release`. For example:
134
135```shell
136# If you build with
137ninja -C out/Debug chrome_public_test_apk
138# You can run:
139adb logcat -d | third_party/android_platform/development/scripts/stack
140
141# If you build with
142ninja -C out/android chrome_public_test_apk
143# You can run:
144adb logcat -d | CHROMIUM_OUTPUT_DIR=out/android third_party/android_platform/development/scripts/stack
145# or
146export CHROMIUM_OUTPUT_DIR=out/android
147adb logcat -d | third_party/android_platform/development/scripts/stack
148```
andybons3322f762015-08-24 21:37:09149
mlamouri0fbd6cd2015-10-26 12:08:11150## JUnit tests
151
152JUnit tests are Java unittests running on the host instead of the target device.
153They are faster to run and therefore are recommended over instrumentation tests
154when possible.
155
156The JUnits tests are usually following the pattern of *target*\_junit\_tests,
157for example, `content_junit_tests` and `chrome_junit_tests`.
158
159When adding a new JUnit test, the associated `BUILD.gn` file must be updated.
160For example, adding a test to `chrome_junit_tests` requires to update
161`chrome/android/BUILD.gn`. If you are a GYP user, you will not need to do that
162step in order to run the test locally but it is still required for GN users to
163run the test.
164
165```shell
166# Build the test suite.
Andrew Grieve4fe99742017-11-23 19:43:16167ninja -C out/Default chrome_junit_tests
mlamouri0fbd6cd2015-10-26 12:08:11168
169# Run the test suite.
Andrew Grieve4fe99742017-11-23 19:43:16170out/Default/run_chrome_junit_tests
mlamouri0fbd6cd2015-10-26 12:08:11171
172# Run a subset of tests. You might need to pass the package name for some tests.
Andrew Grieve4fe99742017-11-23 19:43:16173out/Default/run_chrome_junit_tests -f "org.chromium.chrome.browser.media.*"
174```
175
176### Debugging
177
178Similar to [debugging apk targets](android_debugging_instructions.md#debugging-java):
179
180```shell
181out/Default/bin/run_chrome_junit_tests --wait-for-java-debugger
182out/Default/bin/run_chrome_junit_tests --wait-for-java-debugger # Specify custom port via --debug-socket=9999
mlamouri0fbd6cd2015-10-26 12:08:11183```
184
andybons3322f762015-08-24 21:37:09185## Gtests
186
187```shell
188# Build a test suite
jbudorick25c17382016-08-03 18:53:07189ninja -C out/Release content_unittests
andybons3322f762015-08-24 21:37:09190
191# Run a test suite
jbudorick9472f112016-01-27 16:21:56192out/Release/bin/run_content_unittests [-vv]
andybons3322f762015-08-24 21:37:09193
194# Run a subset of tests
jbudorick9472f112016-01-27 16:21:56195out/Release/bin/run_content_unittests [-vv] --gtest-filter ByteStreamTest.*
andybons3322f762015-08-24 21:37:09196```
197
198## Instrumentation Tests
199
200In order to run instrumentation tests, you must leave your device screen ON and
201UNLOCKED. Otherwise, the test will timeout trying to launch an intent.
202Optionally you can disable screen lock under Settings -> Security -> Screen Lock
203-> None.
204
jbudorick9472f112016-01-27 16:21:56205Next, you need to build the app, build your tests, and then run your tests
206(which will install the APK under test and the test APK automatically).
andybons3322f762015-08-24 21:37:09207
208Examples:
209
210ContentShell tests:
211
212```shell
213# Build the code under test
214ninja -C out/Release content_shell_apk
215
216# Build the tests themselves
217ninja -C out/Release content_shell_test_apk
218
jbudorick9472f112016-01-27 16:21:56219# Run the test (will automagically install the APK under test and the test APK)
220out/Release/bin/run_content_shell_test_apk [-vv]
andybons3322f762015-08-24 21:37:09221```
222
newt17e4d242015-08-27 09:07:26223ChromePublic tests:
andybons3322f762015-08-24 21:37:09224
225```shell
226# Build the code under test
newt17e4d242015-08-27 09:07:26227ninja -C out/Release chrome_public_apk
andybons3322f762015-08-24 21:37:09228
229# Build the tests themselves
newt17e4d242015-08-27 09:07:26230ninja -C out/Release chrome_public_test_apk
andybons3322f762015-08-24 21:37:09231
jbudorick9472f112016-01-27 16:21:56232# Run the test (will automagically install the APK under test and the test APK)
233out/Release/bin/run_chrome_public_test_apk [-vv]
andybons3322f762015-08-24 21:37:09234```
235
236AndroidWebView tests:
237
238```shell
ctzsm34f54d62017-04-21 17:04:07239ninja -C out/Release webview_instrumentation_apk
240ninja -C out/Release webview_instrumentation_test_apk
241out/Release/bin/run_webview_instrumentation_test_apk [-vv]
andybons3322f762015-08-24 21:37:09242```
243
ntfschr09699f442017-01-12 22:20:46244In order to run a subset of tests, use -f to filter based on test class/method
245or -A/-E to filter using annotations.
andybons3322f762015-08-24 21:37:09246
247Filtering examples:
248
249```shell
250# Run a test suite
jbudorick9472f112016-01-27 16:21:56251out/Debug/bin/run_content_shell_test_apk
andybons3322f762015-08-24 21:37:09252
253# Run a specific test class
jbudorick9472f112016-01-27 16:21:56254out/Debug/bin/run_content_shell_test_apk -f AddressDetectionTest.*
andybons3322f762015-08-24 21:37:09255
256# Run a specific test method
jbudorick9472f112016-01-27 16:21:56257out/Debug/bin/run_content_shell_test_apk -f \
andybons3322f762015-08-24 21:37:09258AddressDetectionTest#testAddressLimits
259
260# Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest,
261# EnormousTest)
jbudorick9472f112016-01-27 16:21:56262out/Debug/bin/run_content_shell_test_apk -A Smoke
andybons3322f762015-08-24 21:37:09263
264# Run a subset of tests by annotation, such as filtering by Feature
jbudorick9472f112016-01-27 16:21:56265out/Debug/bin/run_content_shell_test_apk -A Feature=Navigation
andybons3322f762015-08-24 21:37:09266```
267
268You might want to add stars `*` to each as a regular expression, e.g.
269`*`AddressDetectionTest`*`
270
Andrew Grieve4fe99742017-11-23 19:43:16271### Debugging
272
273Similar to [debugging apk targets](android_debugging_instructions.md#debugging-java):
274
275```shell
276out/Debug/bin/run_content_shell_test_apk --wait-for-java-debugger
277```
278
279### Deobfuscating Java Stacktraces
280
281If running with `is_debug=false`, Java stacks from logcat need to be fixed up:
282
283```shell
284out/Release/bin/java_deobfuscate out/Release/apks/ChromePublicTest.apk.mapping < stacktrace.txt
285```
286
287Any stacks produced by test runner output will already be deobfuscated.
288
289
andybons3322f762015-08-24 21:37:09290## Running Blink Layout Tests
291
qyearsleyac3af532016-11-16 22:07:32292See [Layout Tests](testing/layout_tests.md).
andybons3322f762015-08-24 21:37:09293
294## Running GPU tests
295
296(e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall)
297
xiaoyin.l1003c0b2016-12-06 02:51:17298See https://www.chromium.org/developers/testing/gpu-testing for details. Use
jbudorick25c17382016-08-03 18:53:07299`--browser=android-content-shell`. Examine the stdio from the test invocation on
300the bots to see arguments to pass to `src/content/test/gpu/run_gpu_test.py`.