Skip to content

[FEATURE] Migrate Java tests from JUnit 4 to JUnit 5 #7473

@wangzhigang1999

Description

@wangzhigang1999

Code of Conduct

Search before asking

  • I have searched in the issues and found no similar issues.

Describe the feature

Migrate the Java test suites in the following Kyuubi-native modules from JUnit 4 to JUnit 5 (Jupiter):

  • kyuubi-rest-client
  • kyuubi-util
  • kyuubi-hive-jdbc
  • externals/kyuubi-data-agent-engine

The vendored Hive beeline tests under kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/ (package org.apache.hive.beeline) stay on JUnit 4 to remain aligned with upstream Hive and minimize sync friction.

Motivation

  • JUnit 4 has been effectively in maintenance mode since 4.13.2 (Feb 2021). Modern test ecosystem (Mockito 5, Testcontainers, Spring Boot 3, etc.) defaults to JUnit 5.
  • JUnit 5's @ParameterizedTest removes the @Parameterized runner boilerplate currently used in kyuubi-hive-jdbc (3 files).
  • @TempDir parameter injection, assertAll, @Nested, and condition annotations (@EnabledIfSystemProperty, etc.) become available for future tests.
  • Our usage is shallow (@Test + @Before/@After + Assert + Parameterized); no @Rule/@ClassRule/Theories, so the migration is mostly mechanical.

Originally suggested in the AGENTS.md review on #7452.

Describe the solution

  • Add junit-bom 5.x to root dependencyManagement; keep junit:junit 4.13.2 for the vendored Hive beeline module.
  • Switch the four target modules' POMs to org.junit.jupiter:junit-jupiter.
  • Mechanical source rewrites:
    • Imports → org.junit.jupiter.api.* / org.junit.jupiter.params.*
    • Annotations: @Before@BeforeEach, @After@AfterEach, @BeforeClass@BeforeAll, @AfterClass@AfterAll
    • Assert.assertXAssertions.assertX (with message arg moved to last position)
    • Assume.assumeTrueAssumptions.assumeTrue
    • @Test(expected = X.class)assertThrows
    • @RunWith(Parameterized.class) + @Parameters@ParameterizedTest + @MethodSource / @ValueSource
  • Static imports only, no wildcard imports (google-java-format).
  • kyuubi-hive-beeline is out of scope — left on JUnit 4 to avoid diverging from upstream Hive's vendored tests.

Additional context

Surfaced during review of #7452:

seems it's time to upgrade to JUnit5 - should be straightforward, as we don't use many JUnit advanced features.

Are you willing to submit PR?

  • Yes. I would be willing to submit a PR with guidance from the Kyuubi community to improve.
  • No. I cannot submit a PR at this time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions