Skip to content

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

Closed
wangzhigang1999 wants to merge 4 commits into
apache:masterfrom
wangzhigang1999:kyuubi-7473-junit5-migration
Closed

[KYUUBI #7473] Migrate Java tests from JUnit 4 to JUnit 5#7474
wangzhigang1999 wants to merge 4 commits into
apache:masterfrom
wangzhigang1999:kyuubi-7473-junit5-migration

Conversation

@wangzhigang1999

@wangzhigang1999 wangzhigang1999 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Why are the changes needed?

Closes #7473.

JUnit 4 has been in maintenance mode since 4.13.2 (Feb 2021); modern Java test deps (Mockito 5, Testcontainers, etc.) target JUnit 5. Our usage is shallow (no @Rule / @ClassRule / Theories), so the migration is mostly mechanical.

Migrates all five modules with Java tests: kyuubi-rest-client, kyuubi-util, kyuubi-hive-jdbc, kyuubi-hive-beeline, and externals/kyuubi-data-agent-engine. Drops the direct junit:junit dependency and junit.version property from the root pom; transitive exclusions are kept. junit-jupiter is pinned to the latest stable, 5.14.4.

How was this patch tested?

build/mvn -Pfast test -pl <module> -am on each of the five modules — all green. kyuubi-data-agent-engine has 7 live tests skipped via Assumptions.assumeTrue (require an external LLM API). dev/reformat clean.

Was this patch authored or co-authored using generative AI tooling?

Assisted-by: Claude:claude-opus-4-7

Comment thread pom.xml Outdated
@wangzhigang1999 wangzhigang1999 marked this pull request as ready for review May 25, 2026 13:33
@wangzhigang1999 wangzhigang1999 force-pushed the kyuubi-7473-junit5-migration branch from 70644df to ac9b18c Compare May 26, 2026 03:33
@wangzhigang1999 wangzhigang1999 marked this pull request as draft May 26, 2026 03:46
- Add junit-bom 5.11.4 to root dependencyManagement; keep junit 4.13.2
  for vendored Hive beeline tests under org.apache.hive.beeline.
- Switch kyuubi-rest-client, kyuubi-util, kyuubi-hive-jdbc and
  kyuubi-data-agent-engine to junit-jupiter only.
- Rewrite imports and annotations (@test, @before -> @beforeeach, ...),
  swap message argument from msg-first to msg-last,
  convert @RunWith(Parameterized.class) to @ParameterizedTest with
  @MethodSource / @valuesource, replace @test(expected=...) with
  assertThrows, and convert Assume.assumeTrue to Assumptions.assumeTrue.
- Use static imports throughout per google-java-format (no class-
  qualified Assertions.X calls, no wildcard imports).
- kyuubi-hive-beeline stays on JUnit 4 to avoid diverging from the
  vendored Apache Hive beeline tests.
@wangzhigang1999 wangzhigang1999 force-pushed the kyuubi-7473-junit5-migration branch from ac9b18c to 5fa8033 Compare May 26, 2026 04:59
Replace assertTrue(expr.equals(literal)) with assertEquals(literal, expr)
in tests touched by the JUnit 5 migration, plus one assertTrue(x == 100)
to assertEquals(100, x). Pure cleanup, no behavior change.

Assisted-by: Claude:claude-opus-4-7
@wangzhigang1999 wangzhigang1999 marked this pull request as ready for review May 26, 2026 08:15
@wangzhigang1999

Copy link
Copy Markdown
Contributor Author

Done — kyuubi-hive-beeline migrated, direct junit:junit dep removed, and bumped to 5.14.4. CI all green.

- Replace assumeTrue(!X.isEmpty()) with assumeFalse(X.isEmpty())
  (review feedback from @aajisaka).
- Replace assertTrue(x instanceof Y) with assertInstanceOf(Y.class, x),
  and use its return value to eliminate the redundant cast where the
  test then accesses Y-specific methods.
- Replace try/catch + fail() patterns with assertThrows.
- Replace Java native `assert` in tests (silently skipped without -ea)
  with proper JUnit assertions.
- Replace assertEquals(true, X) / assertTrue(!X) / assertTrue(X.equals(Y))
  with the canonical assertTrue / assertFalse / assertEquals forms.
- Switch Assertions.X(...) call sites to the static import form for
  consistency with the rest of the migrated suite.
- Replace a couple of wildcard imports (event.*, Mockito.*, java.io.*)
  with explicit imports.
@wangzhigang1999

Copy link
Copy Markdown
Contributor Author

@aajisaka thanks, pushed the assumeFalse(X.isEmpty(), ...) change at both call sites.

While in there I also swept the migrated tests for a few related JUnit 5 idiom polish-ups:

  • assertTrue(x instanceof Y) → assertInstanceOf(Y.class, x) (and used its return value to drop the redundant cast)
  • try { ... ; fail(...) } catch (E) { } → assertThrows
  • native assert (silently skipped without -ea) → JUnit assertions
  • Assertions.X(...) → static-import form, matching the rest of the suite

All touched tests pass locally, including the live LLM suite.

@aajisaka aajisaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@pan3793 pan3793 added this to the v1.12.0 milestone May 28, 2026
@pan3793

pan3793 commented May 29, 2026

Copy link
Copy Markdown
Member

@wangzhigang1999, congrats and welcome to join us as a committer, you should have the write permission on this repo if you set your apache account properly, you can try to merge this PR via the script dev/merge_kyuubi_pr.py (instead of the GitHub merge button). also you may want to open a PR on the apache/kyuubi-website repo to update the committer list.

@wangzhigang1999

Copy link
Copy Markdown
Contributor Author

@wangzhigang1999, congrats and welcome to join us as a committer, you should have the write permission on this repo if you set your apache account properly, you can try to merge this PR via the script dev/merge_kyuubi_pr.py (instead of the GitHub merge button). also you may want to open a PR on the apache/kyuubi-website repo to update the committer list.

Thanks @pan3793! 🎉 Will set things up properly and try the merge script.
PR for apache/kyuubi-website coming soon!

@pan3793

pan3793 commented May 29, 2026

Copy link
Copy Markdown
Member

@wangzhigang1999, we usually leave a comment after merging, like "merged to xxx/xxx", in case users may confuse the PR state as Closed.

@wangzhigang1999

Copy link
Copy Markdown
Contributor Author

merged to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants