Skip to content

test: migrate unit tests from JUnit 4 to JUnit 6 - #6276

Merged
2dust merged 1 commit into
2dust:masterfrom
aleksandr-miheichev:test/migrate-to-junit6
Oct 1, 2026
Merged

2dust merged 1 commit into
2dust:masterfrom
aleksandr-miheichev:test/migrate-to-junit6

Conversation

@aleksandr-miheichev

@aleksandr-miheichev aleksandr-miheichev commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

JUnit 4, which runs the app's unit tests, is in maintenance mode: only critical bugs and security issues get fixed, and 4.13.2 from February 2021 is its last release. This moves the tests to JUnit Jupiter 6.1.3; the test sources change only mechanically, and the app and its dependencies do not change.

What changes

Unit test tasks run on the JUnit Platform with the Jupiter engine. junit:junit is replaced by the JUnit 6.1.3 BOM, junit-jupiter and junit-platform-launcher; the launcher is declared because Gradle 9 no longer adds it by itself.

The test sources get only the standard replacements:

JUnit 4 JUnit Jupiter
org.junit.Test, org.junit.Assert.* org.junit.jupiter.api.Test, org.junit.jupiter.api.Assertions.*
@Before, @After, @BeforeClass @BeforeEach, @AfterEach, @BeforeAll
@get:Rule val temporaryFolder = TemporaryFolder() @TempDir lateinit var tempDir: File
assertFalse("message", condition) assertFalse(condition, "message"): the message goes last

Why junit.platform.discovery.issue.severity.critical=WARNING

JUnit 4 fails the run on an invalid @Test method, such as one that returns a value. Jupiter only reports a warning and skips the method, and the Gradle output does not show it. This can happen here: DialerWebviewServiceTest.callbacksCannotResumeADestroyedViewOrRescheduleKeepAlive is written as (): Unit = Fixture().use { ... } because its last call returns a Boolean; without the : Unit, JUnit 4 rejects it, and Jupiter would silently not run it.

The setting turns every Jupiter discovery warning into a failure of the test task, so a blank @DisplayName or a malformed @Tag fails it too; the tests use neither today. When it triggers, the task reports a single initializationError, and the test report lists the issues. The key is marked experimental in JUnit 6, so the comment next to it says how to re-check it after a JUnit upgrade.

Open pull requests

14 open pull requests add JUnit 4 tests, for example #5903, #6135, #6252 and #6263. After this is merged, those tests will not compile until they get the replacements from the table above. CI builds only the APKs and will not show this; :app:testPlaystoreDebugUnitTest will. The JUnit Vintage engine, which would keep running JUnit 4 tests unchanged, is deprecated as of JUnit 6.0, so this PR does not add it.

The junit line in libs.versions.toml is next to the coreKtx line changed by #6271, so whichever of the two is merged second needs a one-line rebase. With #6272–#6275 this merges cleanly.

Verification

On Windows with JDK 21, as in CI:

  • :app:testPlaystoreDebugUnitTest and :app:testFdroidDebugUnitTest: 98 tests, 0 failures, 0 skipped. The executed test classes and methods, read from the XML reports, are the same set as on master under JUnit 4.
  • The same 98 tests pass with chore(deps): update mockito-kotlin to 6.4.0, drop mockito-inline #6273 (Mockito 5.24.0) and chore(build): update Gradle wrapper to 9.8.0 #6274 (Gradle 9.8.0) merged in.
  • A temporary @Test fun probe() = listOf(1) fails the unit test task with a DiscoveryIssueException naming the method; without the setting the task passes and the method does not run.
  • :app:assemblePlaystoreDebug and :app:licenseFdroidReleaseReport succeed. The app's compile and runtime classpaths, debug and release in both flavors, are the same before and after; the license report lists no test dependencies.
  • Not run: the CI workflow, which does not run unit tests.

JUnit 4 is in maintenance mode, and 4.13.2 (February 2021) is its last
release. Move the unit tests to JUnit Jupiter 6.1.3: the JUnit BOM,
junit-jupiter and the Platform launcher replace junit:junit, and the
unit test tasks run on the JUnit Platform. The test sources change only
mechanically: imports, lifecycle annotations, TemporaryFolder to
@tempdir, and the message argument moved last in three assertions.

Jupiter skips an invalid @test method, such as one that returns a
value, with only a warning, where JUnit 4 failed the run. Treat
discovery warnings as failures to keep that behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@2dust
2dust merged commit 5029d75 into 2dust:master Oct 1, 2026
1 check passed
@aleksandr-miheichev
aleksandr-miheichev deleted the test/migrate-to-junit6 branch October 1, 2026 14:39
patterniha added a commit to patterniha/PattNG that referenced this pull request Oct 3, 2026
Brings in 2dust/v2rayNG up to a4dd3d0 (2.3.10): the JUnit 6 test
migration (2dust#6276), mockito-kotlin 6.4.0 (2dust#6273), Gradle 9.8.0 (2dust#6274),
NDK r30 (2dust#6275), the navigation bar theme lint fix (2dust#6259), the main
pager row overlap fix, the Luri Bakhtiari translation update (2dust#6169) and
the dependency updates in libs.versions.toml.

Conflicts:
- build.gradle.kts: versionCode 750 and 2.3.10 as the fallback of the
  pattngVersion property.
- values-bqi-rIR/strings.xml: upstream's translation update, with
  PattNG's own strings and its app_name and notification channel name
  kept.
- ProxyChainMembersTest.kt: upstream's JUnit 6 imports, plus the ones
  PattNG's Aether test needs.

AndroidLibXrayLite (2b1c65d, v26.10.3) and hev-socks5-tunnel
(2.18.0-2-g2cdc169) stay on PattNG's pointers, which contain upstream's.
patterniha added a commit to patterniha/PattNG that referenced this pull request Oct 3, 2026
Upstream moved v2rayNG's unit tests to JUnit 6 and dropped JUnit 4
(2dust#6276), so PattNG's 36 test files of its own no longer compiled. They
change the way upstream's did: imports, @Before/@after to
@BeforeEach/@AfterEach, TemporaryFolder to @tempdir, and the message
moved last in the 54 assertions that have one. The two tests that used
TemporaryFolder.newFolder get a newFolder helper that, like it, fails
when the folder already exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants