-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Provide a standard rule for JUnit testing #10036
Comments
Duplicate of: #2539. |
@davido Can you raise the priority of this somehow? This seems like an ongoing problem (all the way back to 2016), and it hasn't received much attention. |
I cannot raise the priority. I'm a regular Bazel user, like all others. Having said that, Gerrit Code Review project that I also contribute to, extracted re-usable Bazel building blocks called junit_tests(
name = "gerrit-oauth-provider_tests",
srcs = glob(["src/test/java/**/*.java"]),
tags = ["oauth"],
deps = [
":gerrit-oauth-provider__plugin_test_deps",
],
) Others are [1] https://github.com/GerritCodeReview/bazlets/blob/master/tools/junit.bzl |
Closing as dupe of #2539. |
FWIW, there is also ready to use And there is also a TODO in Dagger sources to switch to using that, in https://github.com/google/dagger/blob/master/test_defs.bzl#L22. |
Description of the problem / feature request:
The
java_test
rule is really under-powered. By default, it can only run a single class, which forces users into one of four unpleasant scenarios:Make a
java_test
rule per class. This leads to excessively large BUILD files, and the risk of accidentally forgetting to add a newly created test to the BUILD file. ExampleWrite a hacky Starlark rule to read in all the source
.java
files and generate a Suite class. This is repetitive, error prone, and can't be generally reused. It also depends on the source files, rather than working with a java_library. ExampleMake a single Suite runner and manually add each class without the help of a rule. This combines the problems of both 1 and 2. Example
Make a fully featured Classpath scanning test runner and supporting code. This is the most amount of work, but the most likely to behave correctly. Bazel itself uses this with
ClasspathSuite
. However, this doesn't appear to be standard or reliable. It requires aAllTests.java
file for each test directory. Lastly, it doesn't make sense for the Bazel community to have to replicate this amount of work just to run tests.Therefore I am requesting a standardized TestRunner to be included with Bazel, which can scan the
srcs
anddeps
for classes annotated with@RunWith
. (and possibly be scoped to a Java package.) At Google, there was an internal rule that did this, and it was a pleasure to use:junit4_test_suite
. I think this would be an excellent starting point for making Bazel Java development easy.I realize there are other testing frameworks, but JUnit is the biggest, and it would be a practical trade-off to give it a more first class status.
Feature requests: what underlying problem are you trying to solve with this feature?
Make it trivial to write JUnit tests
What's the output of
bazel info release
?release 1.0.0
The text was updated successfully, but these errors were encountered: