RFR: 8366678: Use JUnit in test/langtools/tools/javac [v5]
Chen Liang
liach at openjdk.org
Thu Sep 18 12:41:00 UTC 2025
On Thu, 18 Sep 2025 12:37:51 GMT, Christian Stein <cstein at openjdk.org> wrote:
>> Please review this change to use JUnit in tests of `test/langtools/tools/javac`.
>>
>> ### Assess Status Quo
>> A local `make test TEST=test/langtools/tools/javac` run before the conversion yields:
>>
>> Test results: passed: 3,938; excluded: 4; did not match keywords: 2; did not meet platform requirements: 2
>> Framework-based tests: 3043 = 2762 TestNG + 281 JUnit
>>
>>
>> ### Perform Automatic Conversion
>> - [junit-convert](
>> https://github.com/lahodaj/netbeans/tree/openjdk-testng-junit-fixes-and-hacks/java/java.openjdk.project/junit-convert)
>>
>> ### Perform Manual Adjustments
>>
>> Some of the following adjustments will be integrated into the `junit-convert` tool.
>>
>> #### Make argument source factory method `static`
>>
>> Method 'public java.lang.Object[][] org.openjdk.tests.javac.FDTest.caseGenerator()'
>> must be static: local factory methods must be static
>> unless the PER_CLASS @testinstance lifecycle mode is used;
>> external factory methods must always be static.
>>
>>
>> #### Make `@AfterAll`-annotated method `static`
>>
>> [ERROR] @afterall method 'public void org.openjdk.tests.vm.FDSeparateCompilationTest.cleanupCompilerCache()'
>> must be static unless the test class
>> is annotated with `@TestInstance(Lifecycle.PER_CLASS)`.
>>
>>
>> #### Remove `static` modifier from `@Test`-annotated methods
>> This configuration error should have been detected by JUnit Jupiter and reported via the Discovery
>> Issues API: https://docs.junit.org/current/user-guide/#running-tests-discovery-issues
>>
>> #### Rename test property to `JUnit.dirs`
>>
>> package org.junit.jupiter.api does not exist
>>
>>
>> #### Add custom test instance factory
>>
>> Class [FDTests] must declare a single constructor
>> Class [MethodReferenceTestKinds] must declare a single constructor
>>
>>
>> ### Results
>> Re-run tests via `make test TEST=test/langtools/tools/javac` after the conversion; yielding:
>>
>> Test results: passed: 3,939; excluded: 4; did not match keywords: 2; did not meet platform requirements: 2
>> Framework-based tests: 3043 = 0 TestNG + 3043 JUnit
>
> Christian Stein has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 10 commits:
>
> - Merge remote-tracking branch 'openjdk/master' into JDK-8366678-use-junit-in-javac-tests
>
> # Conflicts:
> # test/jdk/java/security/SignedJar/spi-calendar-provider/TestSPISigned.java
> - Restore comment - it is unrelated to the JUnit conversion
> - Update to use correct library directories
>
> See also: https://openjdk.org/jtreg/faq.html#how-do-i-find-the-path-for-the-testng-or-junit-jar-files
> - 8361950: Set required version to 8+2
> - 8361950: Update to use jtreg 8
> - Refactor test classes to have a unique constructor
>
> That way, Jupiter doesn't need the help of a custom test instance factory
> - Update copyright year
> - Remove `static` modifier from `@Test`-annotated methods
>
> This configuration error should have been detected
> by JUnit Jupiter and reported via the Discovery
> Issues API:
>
> https://docs.junit.org/current/user-guide/#running-tests-discovery-issues
> - Manual adjustments
>
> - Make argument source factory method `static`
>
> Solves:
> ```
> Method 'public java.lang.Object[][] org.openjdk.tests.javac.FDTest.caseGenerator()'
> must be static: local factory methods must be static
> unless the PER_CLASS @TestInstance lifecycle mode is used;
> external factory methods must always be static.
> ```
>
> - Make `@AfterAll`-annotated method `static`
>
> Solves:
> ```
> [ERROR] @AfterAll method 'public void org.openjdk.tests.vm.FDSeparateCompilationTest.cleanupCompilerCache()'
> must be static unless the test class
> is annotated with `@TestInstance(Lifecycle.PER_CLASS)`.
> ```
>
> - Rename test property to `JUnit.dirs`
>
> Solves:
> ```
> package org.junit.jupiter.api does not exist
> ```
>
> - Add custom test instance factory
>
> Solves:
> ```
> Class [FDTests] must declare a single constructor
> Class [MethodReferenceTestKinds] must declare a single constructor
> ```
> - Initial automatic conversion
>
> https://github.com/lahodaj/netbeans/tree/openjdk-testng-junit-fixes-and-hacks/java/java.openjdk.project/junit-convert
Merge looks trivial
-------------
Marked as reviewed by liach (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/27046#pullrequestreview-3239400608
More information about the compiler-dev
mailing list