blob: 25c447add5b415ec556090d4a5382eec877ae924 [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`
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
Daniel Bratellf73f0df2018-09-24 13:52:49161`chrome/android/BUILD.gn`.
mlamouri0fbd6cd2015-10-26 12:08:11162
163```shell
164# Build the test suite.
Andrew Grieve4fe99742017-11-23 19:43:16165ninja -C out/Default chrome_junit_tests
mlamouri0fbd6cd2015-10-26 12:08:11166
167# Run the test suite.
Andrew Grieve4fe99742017-11-23 19:43:16168out/Default/run_chrome_junit_tests
mlamouri0fbd6cd2015-10-26 12:08:11169
170# Run a subset of tests. You might need to pass the package name for some tests.
Andrew Grieve4fe99742017-11-23 19:43:16171out/Default/run_chrome_junit_tests -f "org.chromium.chrome.browser.media.*"
172```
173
174### Debugging
175
176Similar to [debugging apk targets](android_debugging_instructions.md#debugging-java):
177
178```shell
179out/Default/bin/run_chrome_junit_tests --wait-for-java-debugger
180out/Default/bin/run_chrome_junit_tests --wait-for-java-debugger # Specify custom port via --debug-socket=9999
mlamouri0fbd6cd2015-10-26 12:08:11181```
182
andybons3322f762015-08-24 21:37:09183## Gtests
184
185```shell
186# Build a test suite
jbudorick25c17382016-08-03 18:53:07187ninja -C out/Release content_unittests
andybons3322f762015-08-24 21:37:09188
189# Run a test suite
jbudorick9472f112016-01-27 16:21:56190out/Release/bin/run_content_unittests [-vv]
andybons3322f762015-08-24 21:37:09191
192# Run a subset of tests
jbudorick9472f112016-01-27 16:21:56193out/Release/bin/run_content_unittests [-vv] --gtest-filter ByteStreamTest.*
andybons3322f762015-08-24 21:37:09194```
195
196## Instrumentation Tests
197
198In order to run instrumentation tests, you must leave your device screen ON and
199UNLOCKED. Otherwise, the test will timeout trying to launch an intent.
200Optionally you can disable screen lock under Settings -> Security -> Screen Lock
201-> None.
202
jbudorick9472f112016-01-27 16:21:56203Next, you need to build the app, build your tests, and then run your tests
204(which will install the APK under test and the test APK automatically).
andybons3322f762015-08-24 21:37:09205
206Examples:
207
208ContentShell tests:
209
210```shell
211# Build the code under test
212ninja -C out/Release content_shell_apk
213
214# Build the tests themselves
215ninja -C out/Release content_shell_test_apk
216
jbudorick9472f112016-01-27 16:21:56217# Run the test (will automagically install the APK under test and the test APK)
218out/Release/bin/run_content_shell_test_apk [-vv]
andybons3322f762015-08-24 21:37:09219```
220
newt17e4d242015-08-27 09:07:26221ChromePublic tests:
andybons3322f762015-08-24 21:37:09222
223```shell
224# Build the code under test
newt17e4d242015-08-27 09:07:26225ninja -C out/Release chrome_public_apk
andybons3322f762015-08-24 21:37:09226
227# Build the tests themselves
newt17e4d242015-08-27 09:07:26228ninja -C out/Release chrome_public_test_apk
andybons3322f762015-08-24 21:37:09229
jbudorick9472f112016-01-27 16:21:56230# Run the test (will automagically install the APK under test and the test APK)
231out/Release/bin/run_chrome_public_test_apk [-vv]
andybons3322f762015-08-24 21:37:09232```
233
234AndroidWebView tests:
235
236```shell
ctzsm34f54d62017-04-21 17:04:07237ninja -C out/Release webview_instrumentation_apk
238ninja -C out/Release webview_instrumentation_test_apk
239out/Release/bin/run_webview_instrumentation_test_apk [-vv]
andybons3322f762015-08-24 21:37:09240```
241
ntfschr09699f442017-01-12 22:20:46242In order to run a subset of tests, use -f to filter based on test class/method
243or -A/-E to filter using annotations.
andybons3322f762015-08-24 21:37:09244
245Filtering examples:
246
247```shell
248# Run a test suite
jbudorick9472f112016-01-27 16:21:56249out/Debug/bin/run_content_shell_test_apk
andybons3322f762015-08-24 21:37:09250
251# Run a specific test class
jbudorick9472f112016-01-27 16:21:56252out/Debug/bin/run_content_shell_test_apk -f AddressDetectionTest.*
andybons3322f762015-08-24 21:37:09253
254# Run a specific test method
jbudorick9472f112016-01-27 16:21:56255out/Debug/bin/run_content_shell_test_apk -f \
andybons3322f762015-08-24 21:37:09256AddressDetectionTest#testAddressLimits
257
258# Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest,
259# EnormousTest)
jbudorick9472f112016-01-27 16:21:56260out/Debug/bin/run_content_shell_test_apk -A Smoke
andybons3322f762015-08-24 21:37:09261
262# Run a subset of tests by annotation, such as filtering by Feature
jbudorick9472f112016-01-27 16:21:56263out/Debug/bin/run_content_shell_test_apk -A Feature=Navigation
andybons3322f762015-08-24 21:37:09264```
265
266You might want to add stars `*` to each as a regular expression, e.g.
267`*`AddressDetectionTest`*`
268
Andrew Grieve4fe99742017-11-23 19:43:16269### Debugging
270
271Similar to [debugging apk targets](android_debugging_instructions.md#debugging-java):
272
273```shell
274out/Debug/bin/run_content_shell_test_apk --wait-for-java-debugger
275```
276
277### Deobfuscating Java Stacktraces
278
279If running with `is_debug=false`, Java stacks from logcat need to be fixed up:
280
281```shell
282out/Release/bin/java_deobfuscate out/Release/apks/ChromePublicTest.apk.mapping < stacktrace.txt
283```
284
285Any stacks produced by test runner output will already be deobfuscated.
286
287
andybons3322f762015-08-24 21:37:09288## Running Blink Layout Tests
289
qyearsleyac3af532016-11-16 22:07:32290See [Layout Tests](testing/layout_tests.md).
andybons3322f762015-08-24 21:37:09291
292## Running GPU tests
293
294(e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall)
295
xiaoyin.l1003c0b2016-12-06 02:51:17296See https://www.chromium.org/developers/testing/gpu-testing for details. Use
jbudorick25c17382016-08-03 18:53:07297`--browser=android-content-shell`. Examine the stdio from the test invocation on
298the bots to see arguments to pass to `src/content/test/gpu/run_gpu_test.py`.