java_test()
java_test()
rule is used to define a set of .java
files that contain tests to run via JUnit.Arguments
name
(required) #The short name for this build target.
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'])
.resources
(defaults to[]
) #Same as
java_library()
.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
.source
(defaults to'6'
) #Java language level for compiling. Corresponds to the
-source
argument forjavac
.target
(defaults to'6'
) #Bytecode target level for compiling. Corresponds to the
-target
argument forjavac
.deps
(defaults to[]
) #Same as
java_library()
. 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.test_type
(defaults tojunit
) #Specifies which test framework to use. The currently supported options are 'junit' and 'testng'.
run_test_separately
(defaults toFalse
) #If set to
True
, the test(s) in this rule are run separately from all other tests. (This is useful for integration tests which access a physical device or other limited resource.)If unset, the test(s) in this rule in parallel with all other tests.
fork_mode
(defaults toNone
) #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.
test_rule_timeout_ms
(defaults toNone
) #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[test].rule_timeout
.std_out_log_level
(defaults toFINE
) #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.std_err_log_level
(defaults toWARNING
) #Same as
std_out_log_level
, but for std err.use_cxx_libraries
(defaults toFalse
) #Whether or not to build and link against
cxx_library
dependencies when testing.cxx_library_whitelist
(defaults to[]
) #EXPERIMENTAL. List of cxx_libraries to build, if use_cxx_libraries is true. This can be useful if some dependencies are Android-only and won't build on the default platform.
contacts
(defaults to[]
) #A list of organizational contacts for this test. These could be individuals who you would contact in the event of a test failure or other issue with the test.
contacts = [ 'Joe Sixpack', 'Erika Mustermann' ]
vm_args
(defaults to[]
) #Runtime arguments to the JVM running the tests.
env
(defaults to{}
) #A map of environment names and values to set when running the test.
visibility
(defaults to[]
) #List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their
deps
orexported_deps
attributes. For more information, see visibility.licenses
(defaults to[]
) #Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use
buck query
.labels
(defaults to[]
) #Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using
buck query attrfilter()
.