--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAEi%3DzJNe95J8LOmB7q8_qXoZO4tg5ksdJHdPumgO6W8WpJq_KA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/8dfdf22c-07c6-447b-b412-bbd4ce678b3e%40googlegroups.com.
Thanks, I'll look into it.
I'll need to finalize our requirements and see.
Damien,
Can you elaborate some more on the plans for removing the need?
Spent quite a bit of time on understanding how this currently works and would rather not build elaborate constructs if the basis is under consideration
That will solve most issues but why is that preferred to having my own Filename runner?AFAIU your solution will also mandate a macro (so people don't repeat the loop everywhere) and they will share the deps (since I want to save that management overhead) so that sounds very similar.My current plan, if I don't find one better, is to write a macro that will call java_test with the main_class set to the new runner. Sounds very similar.Actually come to think of it, your solution will enable parallelization of the targets, right?It doesn't solve caching (since they share the deps) but enables parallelization.
Am I correct? If so it sounds like you're correct though I don't know the "costs" of a lot of java_test
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAN3hOS_5i84WK2t2wA4VEw6PnEKGq7oXW_gvXXCgj3e3bkWqBQ%40mail.gmail.com.
I don't quite understand the resolution of this thread. What's the preferred way to run a set of tests in a single java_test target? It seems like there are a few options, each with different tradeoffs:1. Write a skylark rule that will generate a suite based on files.2. Use a custom RunWith runner that will generate a suite on the fly.It seems like bazel does #2, but the code is all internal. We'd have to write our own, or extract it somehow. It looks like there are some similar open source libraries, but I couldn't get them working in my short spikes (and they look fairly dead with no updates in over a year).
Is the bazel team planning on adding this functionality directly to bazel? I liked the old behavior, where I could just specify a glob in srcs and bazel would run everything it found. I think this matches how other java build tools tend to do it. I tried to switch back to the legacy behavior, but it does not seem to work with bazel 0.3.0.
# //javatests/io/bazel/project/package/BUILD
java_test(
name = "FooTest",
size = "small",
srcs = ["FooTest.java"],"//third_party/java/junit",
deps = [
"//java/io/bazel/project/package",
"//third_party/java/guava","//third_party/java/truth",
],)java_test(name = "BarTest",size = "small",srcs = ["BarTest.java"],deps = ["//java/io/bazel/project/package","//third_party/java/junit",
"//third_party/java/mockito","//third_party/java/truth",],)
bazel test //javatests/... --test_output=errors
# //javatests/io/bazel/project/package/BUILD
load("//somewhere:GenTestRules.bzl", "GenTestRules")
java_library(
name = "package",
srcs = glob(["*.java"]),
deps = ["//java/io/bazel/project/package","//third_party/java/junit","//third_party/java/guava","//third_party/java/mockito","//third_party/java/truth",],)GenTestRules(name = "GeneratedTestRules",test_files = glob(["*Test.java"]),deps = [":package"],)
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAMXKpGCFeT52DQsY0cO%2BdEY%2BDU6%2B%3DJ269wiSZALnpfm8UVecow%40mail.gmail.com.
The JVM startup penalty problem is easily solved for Java compilation using --strategy=Javac=worker.Is java_test() able to run as a worker too? If not, I hope Bazel will support that in the near future.
Half a year has passed. Maybe some new convenient way of running multiple tests appeared?
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/MFYYkJk1tFs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/05dce314-46f7-4343-885a-e1ec297377ab%40googlegroups.com.
1) One java_test per JUnit test -- "The best practice way to test Java in Bazel is to have a single java_test() rule for every single FooTest.java file"
2) One java_test per directory using the AllTests suite approach, auto-java-test, or GenTestRules
3) something else
If java_test per test class is the best practice, the overhead of generating the rules via a script is not too bad -- I did that to migrate our Gradle build to a set of java_library rules per package.
Thanks!
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0d332b3f-51cf-4a7f-87a3-6910fce4e2c6%40googlegroups.com.
https://bazel.build/versions/master/docs/be/java.html#java_test
The java_test example target is missing the "test_class" attribute. Adding that and using a ClasspathSuite, I can get it to run. However, I could not get it to successfully find the test classes using the ClasspathSuites available. Any tips? Here's what I tried
https://gist.github.com/robfig/b2ae93b90dd93382dbf7e225e91b3659
It looks like the ClasspathSuite in the bazel testutil package might be useful, but it seemed quite overkill to import a huge jar for that functionality, nor did it look easy to transplant just the classes involved.
Alternatively, it looks like this skylark rule might be the easiest thing, but I was hoping to stick to official rules as much as possible.
https://github.com/bazelbuild/bazel/issues/2539
Any advice?
Thanks,
Rob
# BUILDjava_test(name = "FooTestSuite",size = "small",
srcs = glob(["*.java"]),
deps = ["@junit"],)// FooTestSuite.java/** Test suite for foo package. */@RunWith(Suite.class)@SuiteClasses({FooTest.class,BarTest.class,// etc.})public class FooTestSuite {}
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/8fc84dfa-d855-461c-9605-5ab15f0da602%40googlegroups.com.
Thanks for that option. I was really hoping to avoid having to list all tests individually though. Developers here don't have to explicitly list tests today, adding a new *Test.java target in a directory is sufficient to have it run. Besides the extra book-keeping, it would also lead to scenarios where tests are accidentally not being run in continuous integration (they may have developed and run it only in Eclipse, for example)
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/MFYYkJk1tFs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0f2a00d4-e766-46db-992b-3bd524817488%40googlegroups.com.
# foo.bzl
def jart_java_test(name, srcs, package, **kwargs):cmd = ["(","echo 'package %s;'" % package,"echo 'import org.junit.runner.RunWith;'","echo 'import org.junit.runners.Suite;'","echo 'import org.junit.runners.Suite.SuiteClasses;'","echo '@RunWith(Suite.class)'","echo '@SuiteClasses({'"]for src in srcs:if src.endswith("Test.java"):cmd.append("echo ' %s.class,'" % src)cmd.append("echo 'public class %s {}'" % name)
cmd.append(") >$@")
native.genrule(name=name + "_testsuite",outs=[name + ".java"],cmd="\n".join(cmd),
testonly=1,
visibility=["//visibility:private"])native.java_test(name=name, srcs=srcs + [name + ".java"], **kwargs)
# BUILD
load("//:foo.bzl", "jart_java_test")
jart_java_test(
name = "FooTestSuite",size = "small",
package = "com.doodle",
srcs = glob(["*.java"]),deps = ["@junit"],)
Thanks for that option. I was really hoping to avoid having to list all tests individually though. Developers here don't have to explicitly list tests today, adding a new *Test.java target in a directory is sufficient to have it run. Besides the extra book-keeping, it would also lead to scenarios where tests are accidentally not being run in continuous integration (they may have developed and run it only in Eclipse, for example)
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0f2a00d4-e766-46db-992b-3bd524817488%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/MFYYkJk1tFs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/816d5019-4f2c-4c7b-99cc-18d027f15206%40googlegroups.com.
For us this wasn’t good enough since in Scala the fileName and classnames can differ (you can also have multiple classes in a file) so we needed to dynamically discover the relevant classes on runtime.
You can take a look at rules_scala for the implementation.
We’ve been meaning to take it out to its own repo and be jvm agnostic but never got around to it.
Think of it as maven surefire test discovery for Bazel
To unsubscribe from this group and all its topics, send an email to bazel-...@googlegroups.com.