robolectric_test
robolectric_test
def robolectric_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_toolchain: str = "gh_facebook_buck2_shims_meta//:android",
_apple_platforms: dict[str, str] = {},
_build_only_native_code: bool = select({"prelude//android/constraints:build_only_native_code": True, "DEFAULT": False}),
_exec_os_type: str = "prelude//os_lookup/targets:os_lookup",
_inject_test_env: str = "prelude//test/tools:inject_test_env",
_is_building_android_binary: bool = False,
_java_test_toolchain: str = "gh_facebook_buck2_shims_meta//:java_test",
_java_toolchain: str = "gh_facebook_buck2_shims_meta//:java_for_host_test",
_kotlin_toolchain: str = "gh_facebook_buck2_shims_meta//:kotlin",
_remote_test_execution_toolchain: str = "gh_facebook_buck2_shims_meta//:remote_test_execution",
_test_toolchain: str = "gh_facebook_buck2_shims_meta//:test",
abi_generation_mode: None | str = None,
android_optional_jars: None | list[str] = None,
annotation_processing_tool: None | str = None,
annotation_processor_deps: list[str] = [],
annotation_processor_params: list[str] = [],
annotation_processors: list[str] = [],
contacts: list[str] = [],
cxx_library_allowlist: list[str] = [],
default_cxx_platform: None | str = None,
default_host_platform: None | str = None,
deps: list[str] = [],
enable_used_classes: bool = True,
env: dict[str, str] = {},
exported_deps: list[str] = [],
exported_provided_deps: list[str] = [],
extra_arguments: list[str] = [],
extra_kotlinc_arguments: list[str] = [],
fork_mode: str = "none",
friend_paths: list[str] = [],
incremental: bool = False,
jar_postprocessor: None | str = None,
java: None | str = None,
java_agents: list[str] = [],
java_version: None | str = None,
javac: None | str = None,
k2: bool = False,
kotlin_compiler_plugins: dict[str, dict[str, str]] = {},
labels: list[str] = [],
language: None | str = None,
licenses: list[str] = [],
locales_for_binary_resources: list[str] = [],
manifest: None | str = None,
manifest_entries: dict[str, typing.Any] = {},
manifest_file: None | str = None,
maven_coords: None | str = None,
never_mark_as_unused_dependency: None | bool = None,
on_unused_dependencies: None | str = None,
plugins: list[str | (str, list[str])] = [],
preferred_density_for_binary_resources: None | str = None,
proguard_config: None | str = None,
provided_deps: list[str] = [],
provided_deps_query: None | str = None,
remote_execution: None | str | dict[str, None | bool | int | str | list[dict[str, str]] | dict[str, str | list[str]]] = None,
remove_classes: list[str] = [],
required_for_source_only_abi: bool = False,
resource_stable_ids: None | str = None,
resource_union_package: None | str = None,
resources: list[str] = [],
resources_root: None | str = None,
robolectric_runtime_dependencies: list[str] = [],
robolectric_runtime_dependency: None | str = None,
run_test_separately: bool = False,
runtime_deps: list[str] = [],
source: None | str = None,
source_abi_verification_mode: None | str = None,
source_only_abi_deps: list[str] = [],
srcs: list[str] = [],
std_err_log_level: None | int | str = None,
std_out_log_level: None | int | str = None,
target: None | str = None,
test_case_timeout_ms: None | int = None,
test_class_names_file: None | str = None,
test_rule_timeout_ms: None | int = None,
test_type: None | str = None,
unbundled_resources_root: None | str = None,
use_cxx_libraries: None | bool = None,
use_dependency_order_classpath: None | bool = None,
use_jvm_abi_gen: None | bool = None,
used_as_dependency_deprecated_do_not_use: bool = False,
vm_args: list[str] = [],
) -> None
A robolectric_test()
rule is used to define a set of .java
files that contain tests to run via JUnit with Robolectric test runner. It extends from java_test()
rule.
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 -
cxx_library_allowlist
: List of cxx_library targets to build, if use_cxx_libraries is true. This can be useful if some dependencies are Android-only and won't build for the test host platform. -
enable_used_classes
: Deprecated: for an experiment only, will be removed -
extra_kotlinc_arguments
: List of additional arguments to pass into the Kotlin compiler. -
incremental
: Enables Kotlin incremental compilation. -
javac
: Specifies the Java compiler program to use for this rule. The value is a source path or an execution dep (e.g., //foo/bar:bar). Overrides the value in "javac" in the "tools" section of.buckconfig
. -
k2
: Enables the Kotlin K2 compiler. -
kotlin_compiler_plugins
: Use this to specify Kotlin compiler plugins to use when compiling this library. This takes a map, with each entry specify one plugin. Entry's key is plugin source path, and value is a map of plugin option key value pair. Unlikeextra_kotlinc_arguments
, these can be source paths, not just strings.A special option value is
__codegen_dir__
, in which case Buck will provide a default codegen folder's path as option value instead. E.g.fbcode/buck2/prelude/decls/jvm_common.bzl
kotlin_compiler_plugins = {
"somePluginSourcePath": {
"plugin:somePluginId:somePluginOptionKey": "somePluginOptionValue",
"plugin:somePluginId:someDirectoryRelatedOptionKey": "__codegen_dir__",
},
},Each plugin source path will be prefixed with
-Xplugin=
and passed as extra arguments to the compiler. Plugin options will be appended after its plugin with-P
.A specific example is, if you want to use kotlinx.serialization with
kotlin_library()
, you need to specifykotlinx-serialization-compiler-plugin.jar
underkotlin_compiler_plugins
andkotlinx-serialization-runtime.jar
(which you may have to fetch from Maven) in yourdeps
:
kotlin_library(
name = "example",
srcs = glob(["*.kt"]),
deps = [
":kotlinx-serialization-runtime",
],
kotlin_compiler_plugins = {
# Likely copied from your $KOTLIN_HOME directory.
"kotlinx-serialization-compiler-plugin.jar": {},
},
)
prebuilt_jar(
name = "kotlinx-serialization-runtime",
binary_jar = ":kotlinx-serialization-runtime-0.10.0",
)
# Note you probably want to set
# maven_repo=http://jcenter.bintray.com/ in your .buckconfig until
# https://github.com/Kotlin/kotlinx.serialization/issues/64
# is closed.
remote_file(
name = "kotlinx-serialization-runtime-0.10.0",
out = "kotlinx-serialization-runtime-0.10.0.jar",
url = "mvn:org.jetbrains.kotlinx:kotlinx-serialization-runtime:jar:0.10.0",
sha1 = "23d777a5282c1957c7ce35946374fff0adab114c"
) -
manifest
: An optional Android Manifest for the to declare any permissions or intents it may need or want to handle. May either be a file or anandroid_manifest()
target. -
robolectric_runtime_dependency
: Robolectric only runs in offline mode with buck. Specify the relative directory containing all the jars Robolectric uses at runtime.