I am adding tests in Bazel, but I don't want to write a test rule for every single test file. However, each test rule requires a test_class - the test class that is being ran, so there is no easy way to just run all tests with a single java_test rule. Is there a work around for where I wouldn't need to specify a test_class and just run all tests at once?
By default, Bazel runs tests in a parallel fashion to speed things up.
When running a build or a test, Bazel does the following: Loads the BUILD files relevant to the target. Analyzes the inputs and their dependencies, applies the specified build rules, and produces an action graph. Executes the build actions on the inputs until the final build outputs are produced.
To run Bazel, go to your base workspace directory or any of its subdirectories and type bazel . % bazel help [Bazel release bazel-<version>] Usage: bazel <command> <options> ... Available commands: analyze-profile Analyzes build profile data. aquery Executes a query on the post-analysis action graph.
Debugging Bazel To debug the C++ client, run it from gdb or lldb as usual. However, to debug Java code, attach to the server using the following: Run Bazel with the debugging option --host_jvm_debug before the command (such as bazel --host_jvm_debug build //src:bazel ). Attach a debugger to the port 5005.
In Bazel, we wrote a custom Junit Suite that finds all the Junit classes on the classpath in or under the package of the annotated class. You can find the code here. It's pretty short and straight forward and you can copy it into your project or do something similar.
You can then have your rules like this:
java_library(
name = "tests",
testonly = 1,
srcs = glob(["*.java"])
)
java_test(
name = "MyTests",
test_class = "MyTests",
runtime_deps = [":tests"],
)
and the MyTests.java file should look like this:
import package.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class MyTests { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With