Java test ignore pattern *Abstract*Test.class

419 views
Skip to first unread message

tibo...@googlemail.com

unread,
Sep 5, 2015, 4:17:36 AM9/5/15
to bazel-discuss
Hi,

i am trying to make a Maven-built project build with Bazel. I struggle with getting the unit tests to pass because of abstact Classes name FooAbstractTest.java or AbstractFooTest.java. Several other build tools have tiher ignore rules by default or allow to specify such ignore rules.
I believe jUnit also allows to ignore classes but only since version 4.12.

Is there some obvious way to achieve this that I am missing? My current state is:

java_library(
name = "commons-math",
srcs = glob(["src/main/java/**/*.java"])
)

java_library(
name = "test_helpers",
srcs = glob(
["src/test/java/**/*.java"],
exclude = ["src/test/java/**/*Test.java"]
),
deps = [
':commons-math',
'@junit//jar',
'@hamcrest-all//jar',
],
)

java_test(
name = "commons-math-tests",
srcs = glob(["src/test/java/**/*Test.java"]),
deps = [
':commons-math',
':test_helpers',
'@junit//jar',
'@hamcrest-all//jar',
],
)

I guess my other alternatives are using @Ignore annotations or splitting up the tests into different subfolders (like src/test and src/testSupport).

tibo...@googlemail.com

unread,
Sep 5, 2015, 4:38:59 AM9/5/15
to bazel-discuss, tibo...@googlemail.com

Sorry, found a workaround myself:

java_library(
name = "test_helpers",
srcs = glob(
["src/test/java/**/*.java"]

),
deps = [
':commons-math',
'@junit//jar',
'@hamcrest-all//jar',
],
)

java_test(
name = "commons-math-tests",

srcs = glob(["src/test/java/**/*Test.java"],
exclude = ["src/test/java/**/*Abstract*Test.java"]),
resources = glob(["src/test/resource/**/*.*"]),


deps = [
':commons-math',
':test_helpers',
'@junit//jar',
'@hamcrest-all//jar',
],
)

Note this is not a clean solution, so it's not recommended to be copied. But it works for my purposes.

Christian Gruber

unread,
Sep 5, 2015, 2:28:08 PM9/5/15
to tibo...@googlemail.com, bazel-discuss
I'm not sure it's an "unclean" solution.  That's the pattern we use in some of our open-source projects in google, where we maintain two build systems. 

--
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/18b7e54b-9d74-4b89-b82f-766049f55462%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tibo...@googlemail.com

unread,
Sep 5, 2015, 2:42:03 PM9/5/15
to bazel-discuss, tibo...@googlemail.com
I consider it 'unclean' in the respect that it violates DRY. The dependencies have to be specified in duplicate (I think).

IMO, one should generally not need to define both a java_library with tests and a java_test.

In this case I only do so because the two rules could not be unified in one with the tests still running.

I pointed to some cleaner alternatives earlier (like @Ignore), and there might also be other cleaner alternatives when structuring the build files differently.

Kristina Chodorow

unread,
Sep 8, 2015, 11:42:32 AM9/8/15
to tibo...@googlemail.com, bazel-discuss
You could also create a Skylark macro that would wrap the logic you want in a single rule, if that feels better to you.

--
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.
Reply all
Reply to author
Forward
0 new messages