java_test
A java_test()
rule is used to define a set of .java
files that contain tests to run via JUnit.
Function Signature
def java_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 = [],
_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",
_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,
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] = [],
deps_query: None | str = None,
env: dict[str, str] = {},
exported_deps: list[str] = [],
exported_provided_deps: list[str] = [],
extra_arguments: list[str] = [],
fork_mode: str = "none",
jar_postprocessor: None | str = None,
java: None | str = None,
java_agents: list[str] = [],
java_version: None | str = None,
javac: None | str = None,
labels: list[str] = [],
licenses: list[str] = [],
manifest_file: None | str = None,
maven_coords: None | str = None,
never_mark_as_unused_dependency: None | bool = None,
non_exec_dep_plugins_deprecated: list[str | (str, list[str])] = [],
on_unused_dependencies: None | str = None,
plugins: list[str | (str, list[str])] = [],
proguard_config: None | str = None,
provided_deps: list[str] = [],
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,
resources: list[str] = [],
resources_root: None | str = None,
run_test_separately: bool = False,
runner: None | str = None,
runtime_deps: list[str] = [],
source: None | str = None,
source_abi_verification_mode: None | str = None,
source_only_abi_deps: list[str] = [],
specs: None | str = None,
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,
vm_args: list[str] = [],
) -> 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
-
cxx_library_allowlist
: (defaults to:[]
)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.
-
deps
: (defaults to:[]
)Same as
java_library()
. // org.junit.rules.Timeout was not introduced until 4.7. Must include JUnit (version 4.7 or later) as a dependency for JUnit tests. Must include TestNG (version 6.2 or later) and hamcrest as a dependencies for TestNG tests. -
env
: (defaults to:{}
)A map of environment names and values to set when running the test.
-
fork_mode
: (defaults to:"none"
)Controls whether tests will all be run in the same process or a process will be started for each set of tests in a class.
(This is mainly useful when porting Java tests to Buck from Apache Ant which allows JUnit tasks to set a
fork="yes"
property. It should not be used for new tests since it encourages tests to not cleanup after themselves and increases the tests' computational resources and running time.)none
All tests will run in the same process.per_test
A process will be started for each test class in which all tests of that test class will run. -
javac
: (defaults to:None
)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
. -
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
-
non_exec_dep_plugins_deprecated
: (defaults to:[]
)Plugins that do not use the execution platform. This exists for historical reasons, and should not be used. Use
plugins
instead - plugins should be configured for the execution platform since that is where they are used. -
plugins
: (defaults to:[]
)List of plugins that should be run during compilation of the target. A list of strings may additionally be provided in order to pass additional arguments to the plugin.
-
resources
: (defaults to:[]
)Same as
java_library()
. -
source
: (defaults to:None
)Java language level for compiling. Corresponds to the
-source
argument forjavac
. -
srcs
: (defaults to:[]
)Like
java_library()
, all of the.java
files specified by thesrcs
argument will be compiled when this rule is built. In addition, all of the corresponding.class
files that are built by this rule will be passed as arguments to JUnit when this rule is run as a test..class
files that are passed to JUnit that do not have any methods annotated with@Test
are considered failed tests, so make sure that only test case classes are specified assrcs
. This is frequently done by specifyingsrcs
asglob(['**/*Test.java'])
. -
std_err_log_level
: (defaults to:None
)Same as
std_out_log_level
, but for std err. -
std_out_log_level
: (defaults to:None
)Log level for messages from the source under test that buck will output to std out. Value must be a valid
java.util.logging.Level
value. -
target
: (defaults to:None
)Bytecode target level for compiling. Corresponds to the
-target
argument forjavac
. -
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
. -
test_type
: (defaults to:None
)Specifies which test framework to use. The currently supported options are 'junit' and 'testng'.
-
use_cxx_libraries
: (defaults to:None
)Whether or not to build and link against
cxx_library()
dependencies when testing. -
vm_args
: (defaults to:[]
)Runtime arguments to the JVM running the tests.