From b7bd72944a13984f525b7b9d63fba3a5371e831b Mon Sep 17 00:00:00 2001 From: jingwen Date: Fri, 16 Feb 2018 17:10:00 -0800 Subject: Rule documentation for android_instrumentation_test RELNOTES[NEW]: New Android device test rule: android_instrumentation_test. PiperOrigin-RevId: 186067215 --- .../android/AndroidInstrumentationTestRule.java | 80 +++++++++++++++++++++- .../lib/rules/android/AndroidRuleClasses.java | 8 ++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java index c33d060953..d35ee6eba9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java @@ -32,12 +32,23 @@ public class AndroidInstrumentationTestRule implements RuleDefinition { @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) { return builder - .setUndocumented() + /* + The android_binary target containing the test classes. + The android_binary target must specify which target it is testing through + its instruments attribute. + */ .add( attr("test_app", LABEL) .mandatory() .allowedFileTypes(FileTypeSet.NO_FILE) .allowedRuleClasses("android_binary")) + /* +

The android_device the test should run on.

+

To run the test on an emulator that is already running or on a physical device, use + these arguments: + --test_output=streamed --test_arg=--device_broker_type=LOCAL_ADB_SERVER + --test_arg=--device_serial_number=$device_identifier

+ */ .add( attr("target_device", LABEL) .mandatory() @@ -45,12 +56,16 @@ public class AndroidInstrumentationTestRule implements RuleDefinition { .cfg(HostTransition.INSTANCE) .allowedFileTypes(FileTypeSet.NO_FILE) .mandatoryProviders(AndroidDeviceBrokerInfo.PROVIDER.id())) + /* + Other APKs to install on the device before the instrumentation test starts. + */ .add( attr("support_apks", LABEL_LIST) .allowedFileTypes(AndroidRuleClasses.APK) .allowedRuleClasses("android_binary")) .add( attr("fixtures", LABEL_LIST) + .undocumented("Undocumented until the fixtures rules are documented") .allowedFileTypes(FileTypeSet.NO_FILE) .allowedRuleClasses( "android_device_script_fixture", "android_host_service_fixture")) @@ -77,3 +92,66 @@ public class AndroidInstrumentationTestRule implements RuleDefinition { .build(); } } + +/* + +

+ An android_instrumentation_test rule runs Android instrumentation tests. It will + start an emulator, install the application being tested, the test application, and + any other needed applications, and run the tests defined in the test package. +

+

+ The instruments attribute. +

+ +

Example

+ +
+# java/com/samples/hello_world/BUILD
+
+android_library(
+    name = "hello_world_lib",
+    srcs = ["Lib.java"],
+    manifest = "LibraryManifest.xml",
+    resource_files = glob(["res/**"]),
+)
+
+# The app under test
+android_binary(
+    name = "hello_world_app",
+    manifest = "AndroidManifest.xml",
+    deps = [":hello_world_lib"],
+)
+
+ +
+# javatests/com/samples/hello_world/BUILD
+
+android_library(
+    name = "hello_world_test_lib",
+    srcs = ["Tests.java"],
+    deps = [
+      "//java/com/samples/hello_world:hello_world_lib",
+      ...  # test dependencies such as Espresso and Mockito
+    ],
+)
+
+# The test app
+android_binary(
+    name = "hello_world_test_app",
+    instruments = "//java/com/samples/hello_world:hello_world_app",
+    manifest = "AndroidManifest.xml",
+    deps = ["hello_world_test_lib"],
+)
+
+android_instrumentation_test(
+    name = "hello_world_uiinstrumentation_tests",
+    target_device = ":some_target_device",
+    test_app = ":hello_world_test_app",
+)
+
+ +*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java index 81615d0857..cfec36c636 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java @@ -1022,9 +1022,15 @@ public final class AndroidRuleClasses { .cfg(HostTransition.INSTANCE) .exec() .value(env.getToolsLabel("//tools/android:resource_extractor"))) + /* +

The android_binary target to instrument.

+

If this attribute is set, this android_binary will be treated as a test + application for instrumentation tests. An android_instrumentation_test + target can then specify this target in its + test_app attribute. + */ .add( attr("instruments", LABEL) - .undocumented("blocked by android_instrumentation_test") .allowedRuleClasses("android_binary") .allowedFileTypes(NO_FILE)) .add( -- cgit v1.2.3