blob: 69b2cecc3ed2c7bad7d84bc6c6398a85a8c99572 [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
Raphael Kubo da Costafe411ff2018-06-20 08:16:5057[android_emulator.md](android_emulator.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`
ntfschr09699f442017-01-12 22:20:4685- JUnit or Robolectric test files -- i.e., tests that will run on the host --
86 typically belong in `<top-level directory>_junit_tests` (e.g.
87 `base_junit_tests` for `//base`), though here again there are cases
88 (particularly in `//components`) where suites are split at the second
89 directory rather than the top-level one.
andybons3322f762015-08-24 21:37:0990
91Once you know what to build, just do it like you normally would build anything
newt17e4d242015-08-27 09:07:2692else, e.g.: `ninja -C out/Release chrome_public_test_apk`
andybons3322f762015-08-24 21:37:0993
94## Running Tests
95
jbudorick25c17382016-08-03 18:53:0796All functional tests should be runnable via the wrapper scripts generated at
97build time:
98
99```sh
100<output directory>/bin/run_<target_name> [options]
101```
102
103Note that tests are sharded across all attached devices unless explicitly told
104to do otherwise by `-d/--device`.
andybons3322f762015-08-24 21:37:09105
106The commands used by the buildbots are printed in the logs. Look at
xiaoyin.l1003c0b2016-12-06 02:51:17107https://build.chromium.org/ to duplicate the same test command as a particular
andybons3322f762015-08-24 21:37:09108builder.
109
jbudorick25c17382016-08-03 18:53:07110### INSTALL\_FAILED\_CONTAINER\_ERROR or INSTALL\_FAILED\_INSUFFICIENT\_STORAGE
andybons3322f762015-08-24 21:37:09111
jbudorick25c17382016-08-03 18:53:07112If you see this error when the test runner is attempting to deploy the test
andybons3322f762015-08-24 21:37:09113binaries to the AVD emulator, you may need to resize your userdata partition
114with the following commands:
115
116```shell
davve7ae32cd2015-09-22 06:54:09117# Resize userdata partition to be 1G
mikecase7c263052017-03-30 23:46:11118resize2fs android_emulator_sdk/sdk/system-images/android-25/x86/userdata.img 1G
andybons3322f762015-08-24 21:37:09119
120# Set filesystem parameter to continue on errors; Android doesn't like some
121# things e2fsprogs does.
mikecase7c263052017-03-30 23:46:11122tune2fs -e continue android_emulator_sdk/sdk/system-images/android-25/x86/userdata.img
andybons3322f762015-08-24 21:37:09123```
124
125## Symbolizing Crashes
126
ntfschr09699f442017-01-12 22:20:46127Crash stacks are logged and can be viewed using `adb logcat`. To symbolize the
jyasskinc1c76ff2015-12-18 21:39:52128traces, define `CHROMIUM_OUTPUT_DIR=$OUTDIR` where `$OUTDIR` is the argument you
129pass to `ninja -C`, and pipe the output through
130`third_party/android_platform/development/scripts/stack`. If
131`$CHROMIUM_OUTPUT_DIR` is unset, the script will search `out/Debug` and
132`out/Release`. For example:
133
134```shell
135# If you build with
136ninja -C out/Debug chrome_public_test_apk
137# You can run:
138adb logcat -d | third_party/android_platform/development/scripts/stack
139
140# If you build with
141ninja -C out/android chrome_public_test_apk
142# You can run:
143adb logcat -d | CHROMIUM_OUTPUT_DIR=out/android third_party/android_platform/development/scripts/stack
144# or
145export CHROMIUM_OUTPUT_DIR=out/android
146adb logcat -d | third_party/android_platform/development/scripts/stack
147```
andybons3322f762015-08-24 21:37:09148
mlamouri0fbd6cd2015-10-26 12:08:11149## JUnit tests
150
151JUnit tests are Java unittests running on the host instead of the target device.
152They are faster to run and therefore are recommended over instrumentation tests
153when possible.
154
155The JUnits tests are usually following the pattern of *target*\_junit\_tests,
156for example, `content_junit_tests` and `chrome_junit_tests`.
157
158When adding a new JUnit test, the associated `BUILD.gn` file must be updated.
159For example, adding a test to `chrome_junit_tests` requires to update
Daniel Bratellf73f0df2018-09-24 13:52:49160`chrome/android/BUILD.gn`.
mlamouri0fbd6cd2015-10-26 12:08:11161
162```shell
163# Build the test suite.
Andrew Grieve4fe99742017-11-23 19:43:16164ninja -C out/Default chrome_junit_tests
mlamouri0fbd6cd2015-10-26 12:08:11165
166# Run the test suite.
Andrew Grieve4fe99742017-11-23 19:43:16167out/Default/run_chrome_junit_tests
mlamouri0fbd6cd2015-10-26 12:08:11168
169# Run a subset of tests. You might need to pass the package name for some tests.
Andrew Grieve4fe99742017-11-23 19:43:16170out/Default/run_chrome_junit_tests -f "org.chromium.chrome.browser.media.*"
171```
172
173### Debugging
174
175Similar to [debugging apk targets](android_debugging_instructions.md#debugging-java):
176
177```shell
178out/Default/bin/run_chrome_junit_tests --wait-for-java-debugger
179out/Default/bin/run_chrome_junit_tests --wait-for-java-debugger # Specify custom port via --debug-socket=9999
mlamouri0fbd6cd2015-10-26 12:08:11180```
181
andybons3322f762015-08-24 21:37:09182## Gtests
183
184```shell
185# Build a test suite
jbudorick25c17382016-08-03 18:53:07186ninja -C out/Release content_unittests
andybons3322f762015-08-24 21:37:09187
188# Run a test suite
jbudorick9472f112016-01-27 16:21:56189out/Release/bin/run_content_unittests [-vv]
andybons3322f762015-08-24 21:37:09190
191# Run a subset of tests
jbudorick9472f112016-01-27 16:21:56192out/Release/bin/run_content_unittests [-vv] --gtest-filter ByteStreamTest.*
andybons3322f762015-08-24 21:37:09193```
194
195## Instrumentation Tests
196
197In order to run instrumentation tests, you must leave your device screen ON and
198UNLOCKED. Otherwise, the test will timeout trying to launch an intent.
199Optionally you can disable screen lock under Settings -> Security -> Screen Lock
200-> None.
201
jbudorick9472f112016-01-27 16:21:56202Next, you need to build the app, build your tests, and then run your tests
203(which will install the APK under test and the test APK automatically).
andybons3322f762015-08-24 21:37:09204
205Examples:
206
207ContentShell tests:
208
209```shell
210# Build the code under test
211ninja -C out/Release content_shell_apk
212
213# Build the tests themselves
214ninja -C out/Release content_shell_test_apk
215
jbudorick9472f112016-01-27 16:21:56216# Run the test (will automagically install the APK under test and the test APK)
217out/Release/bin/run_content_shell_test_apk [-vv]
andybons3322f762015-08-24 21:37:09218```
219
newt17e4d242015-08-27 09:07:26220ChromePublic tests:
andybons3322f762015-08-24 21:37:09221
222```shell
223# Build the code under test
newt17e4d242015-08-27 09:07:26224ninja -C out/Release chrome_public_apk
andybons3322f762015-08-24 21:37:09225
226# Build the tests themselves
newt17e4d242015-08-27 09:07:26227ninja -C out/Release chrome_public_test_apk
andybons3322f762015-08-24 21:37:09228
jbudorick9472f112016-01-27 16:21:56229# Run the test (will automagically install the APK under test and the test APK)
230out/Release/bin/run_chrome_public_test_apk [-vv]
andybons3322f762015-08-24 21:37:09231```
232
233AndroidWebView tests:
234
235```shell
ctzsm34f54d62017-04-21 17:04:07236ninja -C out/Release webview_instrumentation_apk
237ninja -C out/Release webview_instrumentation_test_apk
238out/Release/bin/run_webview_instrumentation_test_apk [-vv]
andybons3322f762015-08-24 21:37:09239```
240
ntfschr09699f442017-01-12 22:20:46241In order to run a subset of tests, use -f to filter based on test class/method
242or -A/-E to filter using annotations.
andybons3322f762015-08-24 21:37:09243
244Filtering examples:
245
246```shell
247# Run a test suite
jbudorick9472f112016-01-27 16:21:56248out/Debug/bin/run_content_shell_test_apk
andybons3322f762015-08-24 21:37:09249
250# Run a specific test class
jbudorick9472f112016-01-27 16:21:56251out/Debug/bin/run_content_shell_test_apk -f AddressDetectionTest.*
andybons3322f762015-08-24 21:37:09252
253# Run a specific test method
jbudorick9472f112016-01-27 16:21:56254out/Debug/bin/run_content_shell_test_apk -f \
andybons3322f762015-08-24 21:37:09255AddressDetectionTest#testAddressLimits
256
257# Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest,
258# EnormousTest)
jbudorick9472f112016-01-27 16:21:56259out/Debug/bin/run_content_shell_test_apk -A Smoke
andybons3322f762015-08-24 21:37:09260
261# Run a subset of tests by annotation, such as filtering by Feature
jbudorick9472f112016-01-27 16:21:56262out/Debug/bin/run_content_shell_test_apk -A Feature=Navigation
andybons3322f762015-08-24 21:37:09263```
264
265You might want to add stars `*` to each as a regular expression, e.g.
266`*`AddressDetectionTest`*`
267
Andrew Grieve4fe99742017-11-23 19:43:16268### Debugging
269
270Similar to [debugging apk targets](android_debugging_instructions.md#debugging-java):
271
272```shell
273out/Debug/bin/run_content_shell_test_apk --wait-for-java-debugger
274```
275
276### Deobfuscating Java Stacktraces
277
278If running with `is_debug=false`, Java stacks from logcat need to be fixed up:
279
280```shell
281out/Release/bin/java_deobfuscate out/Release/apks/ChromePublicTest.apk.mapping < stacktrace.txt
282```
283
284Any stacks produced by test runner output will already be deobfuscated.
285
286
Kent Tamura59ffb022018-11-27 05:30:56287## Running Blink Web Tests
andybons3322f762015-08-24 21:37:09288
Kent Tamura59ffb022018-11-27 05:30:56289See [Web Tests](testing/web_tests.md).
andybons3322f762015-08-24 21:37:09290
291## Running GPU tests
292
293(e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall)
294
xiaoyin.l1003c0b2016-12-06 02:51:17295See https://www.chromium.org/developers/testing/gpu-testing for details. Use
jbudorick25c17382016-08-03 18:53:07296`--browser=android-content-shell`. Examine the stdio from the test invocation on
297the bots to see arguments to pass to `src/content/test/gpu/run_gpu_test.py`.