feat: Migrate all Java unit tests from JUnit 4 to JUnit Jupiter#2724
Draft
feat: Migrate all Java unit tests from JUnit 4 to JUnit Jupiter#2724
Conversation
Member
Author
|
The javafmt can't run on Java 25:( , in JDK 25 — com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics() is gone |
pjfanning
reviewed
Mar 12, 2026
testkit/src/test/java/org/apache/pekko/testkit/PekkoJUnit5ActorSystemResource.java
Outdated
Show resolved
Hide resolved
558a695 to
50a3952
Compare
Member
Author
|
We should mark JUnit 4 support as deprecated, and mark it since |
He-Pin
commented
Mar 12, 2026
actor-typed-tests/src/test/java/jdocs/org/apache/pekko/typed/StashDocTest.java
Show resolved
Hide resolved
Member
|
Why is this called Junit5 in this new code? v6 is out. I'm thinking about the new classes in this PR
|
Member
Author
|
I will rebase on your current style:) |
He-Pin
added a commit
that referenced
this pull request
Mar 16, 2026
Motivation: JUnit 4 has reached end-of-life and JUnit 5 (Jupiter) provides significant improvements. The project already uses jupiter-engine 6.0.3 and has existing JUnitJupiter-named infrastructure. This migration aligns all test code with the modern Jupiter naming convention. Modification: - Replace @ClassRule/@rule with @RegisterExtension using PekkoJUnitJupiterActorSystemResource (renamed from JUnit5 variant) - Replace StreamTest5 base class with StreamTestJupiter - Replace TestKitJUnit5Extension with TestKitJUnitJupiterExtension - Replace @JUnit5TestKit with @JUnitJupiterTestKit annotation - Replace JUnit5TestKitBuilder with JUnitJupiterTestKitBuilder - Remove extends JUnitSuite (JUnit 4 base class) - Migrate Assert to Assertions, @test(expected=...) to assertThrows() - Add synchronized lifecycle methods for thread safety - Remove printStackTrace from error handling - 105 files changed across all test modules Result: All Java unit tests now use JUnit Jupiter APIs with consistent JUnitJupiter naming convention. JUnit 4 support APIs remain available for downstream users. All tests pass locally. References: - PR review feedback: #2724 (comment) - JUnit 5 User Guide: https://junit.org/junit5/docs/current/user-guide/
He-Pin
added a commit
that referenced
this pull request
Mar 16, 2026
Motivation: JUnit 4 has reached end-of-life and JUnit 5 (Jupiter) provides significant improvements. The project already uses jupiter-engine 6.0.3 and has existing JUnitJupiter-named infrastructure. This migration aligns all test code with the modern Jupiter naming convention. Modification: - Replace @ClassRule/@rule with @RegisterExtension using PekkoJUnitJupiterActorSystemResource (renamed from JUnit5 variant) - Replace StreamTest5 base class with StreamTestJupiter - Replace TestKitJUnit5Extension with TestKitJUnitJupiterExtension - Replace @JUnit5TestKit with @JUnitJupiterTestKit annotation - Replace JUnit5TestKitBuilder with JUnitJupiterTestKitBuilder - Remove extends JUnitSuite (JUnit 4 base class) - Migrate Assert to Assertions, @test(expected=...) to assertThrows() - Add synchronized lifecycle methods for thread safety - Remove printStackTrace from error handling - 105 files changed across all test modules Result: All Java unit tests now use JUnit Jupiter APIs with consistent JUnitJupiter naming convention. JUnit 4 support APIs remain available for downstream users. All tests pass locally. References: - PR review feedback: #2724 (comment) - JUnit 5 User Guide: https://junit.org/junit5/docs/current/user-guide/
Motivation: JUnit 4 has reached end-of-life and JUnit 5 (Jupiter) provides significant improvements. The project already uses jupiter-engine 6.0.3 and has existing JUnitJupiter-named infrastructure. This migration aligns all test code with the modern Jupiter naming convention. Modification: - Replace @ClassRule/@rule with @RegisterExtension using PekkoJUnitJupiterActorSystemResource (renamed from JUnit5 variant) - Replace StreamTest5 base class with StreamTestJupiter - Replace TestKitJUnit5Extension with TestKitJUnitJupiterExtension - Replace @JUnit5TestKit with @JUnitJupiterTestKit annotation - Replace JUnit5TestKitBuilder with JUnitJupiterTestKitBuilder - Remove extends JUnitSuite (JUnit 4 base class) - Migrate Assert to Assertions, @test(expected=...) to assertThrows() - Add synchronized lifecycle methods for thread safety - Remove printStackTrace from error handling - 105 files changed across all test modules Result: All Java unit tests now use JUnit Jupiter APIs with consistent JUnitJupiter naming convention. JUnit 4 support APIs remain available for downstream users. All tests pass locally. References: - PR review feedback: #2724 (comment) - JUnit 5 User Guide: https://junit.org/junit5/docs/current/user-guide/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Migrate all Java unit tests from JUnit 4 patterns (
@ClassRule,@Rule,@RunWith,ExternalResource,extends JUnitSuite) to JUnit 5 Jupiter patterns (@RegisterExtension,@ExtendWith). This improves project maintainability and aligns with the modern testing ecosystem.Additionally, rename all
JUnit5*naming toJUnitJupiter*in test files, since "JUnit Jupiter" is the API name — not tied to version 5. Withjupiter-enginealready at version 6.0.3, usingJUnit5in class names would be misleading.This addresses reviewer feedback from @pjfanning:
Modification
New Files
PekkoJUnitJupiterActorSystemResource.java— JUnit Jupiter extension replacing JUnit 4 Rule-basedPekkoJUnitActorSystemResource. ImplementsBeforeAllCallback,AfterAllCallback,BeforeEachCallback,AfterEachCallback,ParameterResolver. Thread-safe via synchronized methods with aclassLevelflag distinguishing static (class-level) from instance (per-test) lifecycle.StreamTestJupiter.java— Base class for stream tests, replacingStreamTest(JUnit 4 version). Delegates toPekkoJUnitJupiterActorSystemResource.ActorTestKitJUnitJupiterTest.java— Renamed fromActorTestKitJUnit5Test.Migration Patterns Applied (206 files)
@ClassRule public static PekkoJUnitActorSystemResource@RegisterExtension static PekkoJUnitJupiterActorSystemResource@Rule public PekkoJUnitActorSystemResource@RegisterExtension PekkoJUnitJupiterActorSystemResourceextends JUnitSuite@RunWith(JUnitRunner.class)@Test(expected = X.class)assertThrows(X.class, () -> {...})Assert.assertEquals(msg, expected, actual)assertEquals(expected, actual, msg)Assert.assertTrue(msg, condition)assertTrue(condition, msg)extends StreamTestextends StreamTestJupiter@ExtendWith(TestKitJUnit5Extension.class)@ExtendWith(TestKitJUnitJupiterExtension.class)@JUnit5TestKit@JUnitJupiterTestKitJUnit5TestKitBuilderJUnitJupiterTestKitBuilderBackward Compatibility
JUnit5TestKitBuilder,TestKitJUnit5Extension,JUnit5TestKitannotation insrc/mainare preserved (not deleted or deprecated — deprecation is a separate concern per @pjfanning).PekkoJUnitActorSystemResourceandStreamTestpreserved for users who still use JUnit 4.JUnit5TestKitBuilderSpec.scalapreserved as it tests the old builder.Dependencies
junit-jupiter-engine: 6.0.3junit-platform-launcher: 6.0.3sbt-jupiter-interface: 0.17.0junit-interface: 0.11 (for JUnit 4 vintage compatibility)Result
printStackTracecallsReferences
JUnit5naming obsoleteThis code is Apache licensed under the Apache License, Version 2.0.