Skip to content

Commit

Permalink
[java] Run tests on the JUnit Platform (JUnit 5) (#10752)
Browse files Browse the repository at this point in the history
* [java] Use java_test_suite and from contrib_rule_jvm

First step in the migration of the test codebase to JUnit 5

issue #10196

* [java] Manage JUnit 5 dependencies, using junit-vintage for existing tests

Second step in the migration of the test codebase to JUnit 5

issue #10196

* [java] Move interface HasMagicNumbers to a separate class

issue #10196

* [java] Include missing dependencies

issue #10196

* [java] Include additional JUnit 5 dependencies

issue #10196q

* [java] Use JUnit 4 runner by default

Since the existing tests are based on JUnit 4

issue #10196

* [java] Remove lint tests for contrib_rules_jvm macros

Pull java_test and java_library from contrib_rules_jvm
and not from the default packages

issue #10196

* [java] Bump to contrib_rules_jvm version 0.3.0

* [java] Use spotbugs as linter from contrib_rules_jvm

Co-authored-by: Diego Molina <[email protected]>
  • Loading branch information
bonigarcia and diemol authored Jun 9, 2022
1 parent 7c92468 commit f9018c6
Show file tree
Hide file tree
Showing 81 changed files with 702 additions and 328 deletions.
15 changes: 15 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

http_archive(
name = "contrib_rules_jvm",
sha256 = "79773625951a7a6dc0fc1636ef2388253b69a1e8109b34198c191953280648ab",
strip_prefix = "rules_jvm-0.3.0",
url = "https://github.com/bazel-contrib/rules_jvm/archive/v0.3.0.tar.gz",
)

load("@contrib_rules_jvm//:repositories.bzl", "contrib_rules_jvm_deps")

contrib_rules_jvm_deps()

load("@contrib_rules_jvm//:setup.bzl", "contrib_rules_jvm_setup")

contrib_rules_jvm_setup()

load("//java:maven_deps.bzl", "selenium_java_deps")

selenium_java_deps()
Expand Down
4 changes: 2 additions & 2 deletions java/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "spotbugs_config")
load("@contrib_rules_jvm//java:defs.bzl", "spotbugs_config")

exports_files(
srcs = [
Expand Down Expand Up @@ -41,7 +41,7 @@ spotbugs_config(
name = "spotbugs-config",
effort = "default",
exclude_filter = "spotbugs-excludes.xml",
fail_on_warning = True,
fail_on_warning = False,
visibility = [
"//visibility:public",
],
Expand Down
16 changes: 12 additions & 4 deletions java/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ load("//java/private:library.bzl", _java_export = "java_export", _java_library =
load("//java/private:merge_jars.bzl", _merge_jars = "merge_jars")
load("//java/private:module.bzl", _java_module = "java_module")
load("//java/private:selenium_test.bzl", _selenium_test = "selenium_test")
load("//java/private:spotbugs_config.bzl", _spotbugs_config = "spotbugs_config")
load("//java/private:suite.bzl", _java_selenium_test_suite = "java_selenium_test_suite", _java_test_suite = "java_test_suite")
load("//java/private:suite.bzl", _java_selenium_test_suite = "java_selenium_test_suite")
load(
"@contrib_rules_jvm//java:defs.bzl",
_JUNIT5_DEPS = "JUNIT5_DEPS",
_JUNIT5_VINTAGE_DEPS = "JUNIT5_VINTAGE_DEPS",
_java_test_suite = "java_test_suite",
)

def java_test_suite(name, runner = "junit4", **kwargs):
_java_test_suite(name = name, runner = runner, **kwargs)

artifact = _artifact
java_binary = _java_binary
Expand All @@ -21,8 +29,8 @@ java_library = _java_library
java_module = _java_module
java_selenium_test_suite = _java_selenium_test_suite
java_test = _java_test
java_test_suite = _java_test_suite
javadoc = _javadoc
merge_jars = _merge_jars
selenium_test = _selenium_test
spotbugs_config = _spotbugs_config
JUNIT5_DEPS = _JUNIT5_DEPS
JUNIT5_VINTAGE_DEPS = _JUNIT5_VINTAGE_DEPS
10 changes: 10 additions & 0 deletions java/maven_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ load("@rules_jvm_external//:specs.bzl", "maven")
def selenium_java_deps():
netty_version = "4.1.77.Final"
opentelemetry_version = "1.14.0"
junit_jupiter_version = "5.8.2"
junit_platform_version = "1.8.2"

maven_install(
artifacts = [
Expand Down Expand Up @@ -66,6 +68,14 @@ def selenium_java_deps():
"org.hamcrest:hamcrest-library",
],
),
"org.junit.jupiter:junit-jupiter-api:%s" % junit_jupiter_version,
"org.junit.jupiter:junit-jupiter-engine:%s" % junit_jupiter_version,
"org.junit.jupiter:junit-jupiter-params:%s" % junit_jupiter_version,
"org.junit.vintage:junit-vintage-engine:%s" % junit_jupiter_version,
"org.junit.platform:junit-platform-launcher:%s" % junit_platform_version,
"org.junit.platform:junit-platform-reporting:%s" % junit_platform_version,
"org.junit.platform:junit-platform-commons:%s" % junit_platform_version,
"org.junit.platform:junit-platform-engine:%s" % junit_platform_version,
"net.bytebuddy:byte-buddy:1.12.10",
"dev.failsafe:failsafe:3.2.4",
"net.sourceforge.htmlunit:htmlunit-core-js:2.61.1",
Expand Down
474 changes: 472 additions & 2 deletions java/maven_install.json

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions java/private/library.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("@apple_rules_lint//lint:defs.bzl", "get_lint_config")
load(
"@rules_java//java:defs.bzl",
"@contrib_rules_jvm//java:defs.bzl",
"spotbugs_test",
_java_library = "java_library",
_java_test = "java_test",
)
load(":export.bzl", _java_export = "java_export")
load(":spotbugs.bzl", "spotbugs_test")

def add_lint_tests(name, **kwargs):
srcs = kwargs.get("srcs", [])
Expand All @@ -29,14 +29,6 @@ def add_lint_tests(name, **kwargs):
timeout = "moderate",
)

def java_export(name, **kwargs):
add_lint_tests(name, **kwargs)
_java_export(name = name, **kwargs)

def java_library(name, **kwargs):
add_lint_tests(name, **kwargs)
_java_library(name = name, **kwargs)

def java_test(name, **kwargs):
add_lint_tests(name, **kwargs)
_java_test(name = name, **kwargs)
java_export = _java_export
java_library = _java_library
java_test = _java_test
103 changes: 0 additions & 103 deletions java/private/spotbugs.bzl

This file was deleted.

38 changes: 0 additions & 38 deletions java/private/spotbugs_config.bzl

This file was deleted.

4 changes: 2 additions & 2 deletions java/src/com/thoughtworks/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_library")
load("//java:defs.bzl", "JUNIT5_VINTAGE_DEPS", "java_library")

java_library(
name = "api",
Expand Down Expand Up @@ -40,7 +40,7 @@ java_library(
"//java/src/org/openqa/selenium:core",
artifact("junit:junit"),
artifact("org.testng:testng"),
],
] + JUNIT5_VINTAGE_DEPS,
)

java_library(
Expand Down
4 changes: 2 additions & 2 deletions java/src/com/thoughtworks/selenium/condition/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_library")
load("//java:defs.bzl", "JUNIT5_VINTAGE_DEPS", "java_library")

java_library(
name = "condition",
Expand All @@ -10,5 +10,5 @@ java_library(
deps = [
"//java/src/com/thoughtworks/selenium:api",
artifact("junit:junit"),
],
] + JUNIT5_VINTAGE_DEPS,
)
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/lift/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_export")
load("//java:defs.bzl", "JUNIT5_VINTAGE_DEPS", "java_export")
load("//java:version.bzl", "SE_VERSION")

java_export(
Expand All @@ -15,5 +15,5 @@ java_export(
"//java/src/org/openqa/selenium/support",
artifact("org.hamcrest:hamcrest"),
artifact("junit:junit"),
],
] + JUNIT5_VINTAGE_DEPS,
)
6 changes: 3 additions & 3 deletions java/test/com/thoughtworks/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_library", "java_selenium_test_suite")
load("//java:defs.bzl", "JUNIT5_VINTAGE_DEPS", "java_library", "java_selenium_test_suite")

java_library(
name = "test-base",
Expand All @@ -25,7 +25,7 @@ java_library(
"//java/test/org/openqa/selenium/testing/drivers",
artifact("com.google.guava:guava"),
artifact("junit:junit"),
],
] + JUNIT5_VINTAGE_DEPS,
)

java_selenium_test_suite(
Expand Down Expand Up @@ -76,5 +76,5 @@ java_selenium_test_suite(
artifact("com.google.guava:guava"),
artifact("junit:junit"),
artifact("org.mockito:mockito-core"),
],
] + JUNIT5_VINTAGE_DEPS,
)
4 changes: 2 additions & 2 deletions java/test/com/thoughtworks/selenium/webdriven/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_selenium_test_suite")
load("//java:defs.bzl", "JUNIT5_VINTAGE_DEPS", "java_selenium_test_suite")

java_selenium_test_suite(
name = "LargeTests",
Expand Down Expand Up @@ -28,5 +28,5 @@ java_selenium_test_suite(
artifact("io.opentelemetry:opentelemetry-api"),
artifact("junit:junit"),
artifact("org.mockito:mockito-core"),
],
] + JUNIT5_VINTAGE_DEPS,
)
8 changes: 4 additions & 4 deletions java/test/org/openqa/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_library", "java_selenium_test_suite", "java_test_suite")
load("//java:defs.bzl", "JUNIT5_VINTAGE_DEPS", "java_library", "java_selenium_test_suite", "java_test_suite")

SMALL_TESTS = [
"ArchitectureTest.java",
Expand Down Expand Up @@ -32,7 +32,7 @@ java_test_suite(
artifact("com.google.guava:guava"),
artifact("junit:junit"),
artifact("org.mockito:mockito-core"),
],
] + JUNIT5_VINTAGE_DEPS,
)

java_library(
Expand All @@ -49,7 +49,7 @@ java_library(
"//java/src/org/openqa/selenium/support",
artifact("com.google.guava:guava"),
artifact("junit:junit"),
],
] + JUNIT5_VINTAGE_DEPS,
)

java_selenium_test_suite(
Expand Down Expand Up @@ -83,5 +83,5 @@ java_selenium_test_suite(
artifact("javax.servlet:javax.servlet-api"),
artifact("org.assertj:assertj-core"),
artifact("xyz.rogfam:littleproxy"),
],
] + JUNIT5_VINTAGE_DEPS,
)
Loading

0 comments on commit f9018c6

Please sign in to comment.