Skip to main content

android_instrumentation_test

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_android_emulators: None | str = ...,
_android_toolchain: str = ...,
_apple_platforms: dict[str, str] = ...,
_exec_os_type: str = ...,
_inject_test_env: str = ...,
_java_test_toolchain: str = ...,
_java_toolchain: str = ...,
_test_toolchain: str = ...,
apk: str,
clear_package_data: bool = ...,
collect_tombstones: bool = ...,
contacts: list[str] = ...,
default_host_platform: None | str = ...,
disable_animations: bool = ...,
env: dict[str, str] = ...,
extra_instrumentation_args: None | dict[str, str] = ...,
instrumentation_test_listener: None | str = ...,
instrumentation_test_listener_class: None | str = ...,
is_self_instrumenting: bool = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
log_extractors: dict[str, str] = ...,
meta_internal_extra_params: None | dict[str, typing.Any] = ...,
re_caps: None | dict[str, dict[str, str]] = ...,
re_use_case: None | dict[str, str] = ...,
record_video: bool = ...,
test_rule_timeout_ms: None | int = ...,
) -> 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',
)