android_instrumentation_test
An android_instrumentation_test()
rule is used to define apks that should be used to run Android instrumentation tests.
Function Signature
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 | (str, 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
Parameters
-
name
: (required)name of the target
-
default_target_platform
: (defaults to:None
)specifies the default target platform, used when no platforms are specified on the command line
-
target_compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
exec_compatible_with
: (defaults to:[]
)a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
-
visibility
: (defaults to:[]
)a list of visibility patterns restricting what targets can depend on this one
-
within_view
: (defaults to:["PUBLIC"]
)a list of visibility patterns restricting what this target can depend on
-
metadata
: (defaults to:{}
)a key-value map of metadata associated with this target
-
tests
: (defaults to:[]
)a list of targets that provide tests for this one
-
modifiers
: (defaults to:[]
)an array of modifiers associated with this target
-
_android_emulators
: (defaults to:None
)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
: (required)The APK containing the tests. Can be an
android_binary()
, anapk_genrule()
or anandroid_instrumentation_apk()
. -
clear_package_data
: (defaults to:False
)Runs
pm clear
on the app and test packages before the test run if set to True. -
collect_tombstones
: (defaults to:False
)Checks whether the test generated any tombstones, and downloads them from the emulator if true.
-
disable_animations
: (defaults to:False
)Disables animations on the emulator if set to True.
-
labels
: (defaults to:[]
)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
orfast
). A label can be used to filter or include a specific test rule when executingbuck test
-
record_video
: (defaults to:False
)Record video of test run and collect it as TRA
-
test_rule_timeout_ms
: (defaults to:None
)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
.
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',
)