Skip to main content

android_instrumentation_test

android_instrumentation_test

def android_instrumentation_test(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_android_emulators: None | str = None,
_android_toolchain: str = "gh_facebook_buck2_shims_meta//:android",
_apple_platforms: dict[str, str] = {},
_exec_os_type: str = "prelude//os_lookup/targets:os_lookup",
_inject_test_env: str = "prelude//test/tools:inject_test_env",
_java_test_toolchain: str = "gh_facebook_buck2_shims_meta//:java_for_host_test",
_java_toolchain: str = "gh_facebook_buck2_shims_meta//:java_for_android",
_test_toolchain: str = "gh_facebook_buck2_shims_meta//:test",
apk: str,
clear_package_data: bool = False,
collect_tombstones: bool = False,
contacts: list[str] = [],
default_host_platform: None | str = None,
disable_animations: bool = False,
env: dict[str, str] = {},
extra_instrumentation_args: None | dict[str, str] = None,
instrumentation_test_listener: None | str = None,
instrumentation_test_listener_class: None | str = None,
is_self_instrumenting: bool = False,
labels: list[str] = [],
licenses: list[str] = [],
log_extractors: dict[str, str] = {},
meta_internal_extra_params: None | dict[str, typing.Any] = None,
re_caps: None | dict[str, dict[str, str]] = None,
re_use_case: None | dict[str, str] = None,
record_video: bool = False,
test_rule_timeout_ms: None | int = None,
) -> None

An android_instrumentation_test() rule is used to define apks that should be used to run Android instrumentation tests.

Parameters

  • name: name of the target
  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line
  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
  • visibility: a list of visibility patterns restricting what targets can depend on this one
  • within_view: a list of visibility patterns restricting what this target can depend on
  • metadata: a key-value map of metadata associated with this target
  • tests: a list of targets that provide tests for this one
  • modifiers: an array of modifiers associated with this target
  • _android_emulators: If provided, local resource of "android_emulators" type will be required to run this test locally and this target will be used to manage it. If omitted, local resource of "android_emulators" type will be ignored even if requested by the test runner.
  • apk: The APK containing the tests. Can be an android_binary(), an apk_genrule() or an android_instrumentation_apk().
  • clear_package_data: Runs pm clear on the app and test packages before the test run if set to True.
  • collect_tombstones: Checks whether the test generated any tombstones, and downloads them from the emulator if true.
  • disable_animations: Disables animations on the emulator if set to True.
  • labels: A list of labels to be applied to these tests. These labels are arbitrary text strings and have no meaning within buck itself. They can, however, have meaning for you as a test author (e.g., smoke or fast). A label can be used to filter or include a specific test rule when executing buck test
  • record_video: Record video of test run and collect it as TRA
  • test_rule_timeout_ms: If set specifies the maximum amount of time (in milliseconds) in which all of the tests in this rule should complete. This overrides the default rule_timeout if any has been specified in .buckconfig .

Details

Examples:

Here is an example of an android_instrumentation_test() rule that tests an android_binary().


android_binary(
name = 'messenger',
manifest = 'AndroidManifest.xml',
keystore = '//keystores:prod',
package_type = 'release',
proguard_config = 'proguard.cfg',
deps = [
...
],
)

android_instrumentation_apk(
name = 'messenger_test',
manifest = 'AndroidInstrumentationManifest.xml',
apk = ':messenger',
deps = [
...
],
)

android_instrumentation_test(
name = 'messenger_instrumentation_test',
apk = ':messenger_test',
)