RFR: 8343876: Enhancements to jpackage test lib [v2]

Alexey Semenyuk asemenyuk at openjdk.org
Fri Nov 15 15:01:20 UTC 2024


> Make jpackage test lib more practical. List of changes:
> 
> Support multiple args and var args in `@Parameter` annotation:
> 
> @Test
> @Parameter({"12", "foo"})
> @Parameter({"-89", "bar", "more"})
> @Parameter({"-89", "bar", "more", "moore"})
> public void testVarArg(int a, String b, String ... other) {}
> 
> 
> Full support for var args in test constructors.<br/>Better results when looking up the suitable ctor for the ctor args with `null`-s.<br/>Support multiple functions with `@Parameteres` annotation, all will be executed instead of the first one earlier:
> 
> class FooTest {
>     public FooTest(String... args) {}
>     public FooTest(int o) {}
>     public FooTest(int a, Boolean[] b, String c, String ... other) {}
> 
>     @Parameters
>     public static Collection<Object[]> input() {
>         return List.of(new Object[][] {
>             {},
>             {"str"},
>             {55, new Boolean[]{false, true, false}, "foo", "bar"},
>         });
>     }
> 
>     @Parameters
>     public static Collection<Object[]> input2() {
>         return List.of(new Object[][] {
>             {78},
>             {34, null, null},
>         });
>     }
> }
> 
> 
> Static test method will be executed only once and not as many times as the number of the test class instances.
> 
> Introduced `@ParameterSupplier` annotation as a flexible alternative to `@Parameter`:
> 
> 
> class FooTest {
>     @Test
>     @ParameterSupplier("dateSupplier")
>     @ParameterSupplier("AnotherClass.dateSupplier")
>     public void testDates(LocalDate v) {}
> 
>     public static Collection<Object[]> dateSupplier() {
>         return List.of(new Object[][] {
>             { LocalDate.parse("2018-05-05") },
>             { LocalDate.parse("2018-07-11") },
>         });
>     }
> }
> 
> class AnotherClass {
>     public static Collection<Object[]> dateSupplier() {
>         return List.of(new Object[][] {
>             { LocalDate.parse("2028-07-11") },
>         });
>     }
> }
> 
> 
> All annotations support `ifOS` and `ifNotOS` properties of type `jdk.internal.util.OperatingSystem`:
> 
> 
> @Test(ifOS = OperatingSystem.LINUX)
> public void testRunIfLinux() {}
> 
> @Test(ifNotOS = OperatingSystem.LINUX)
> public void testRunIfNotLinux() {}
> 
> @Test(ifNotOS = {OperatingSystem.LINUX,OperatingSystem.MACOS})
> public void testRunIfNotLinuxOrMacOS() {}
> 
> @Test
> @Parameter(value = "foo", ifOS = OperatingSystem.LINUX)
> @Parameter(value = {"foo", "bar"}, ifOS = { OperatingSystem.LINUX, OperatingSystem.MACOS })
> @Parameter(value = {}, ifNotOS = { OperatingSystem.WINDOWS })
> @ParameterSupplier(value = "getWindowsStrings", ifOS = OperatingSyst...

Alexey Semenyuk has updated the pull request incrementally with one additional commit since the last revision:

  Fix finding in the review

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/21996/files
  - new: https://git.openjdk.org/jdk/pull/21996/files/1c7e0592..66c1583a

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=21996&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=21996&range=00-01

  Stats: 6 lines in 4 files changed: 1 ins; 1 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/21996.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/21996/head:pull/21996

PR: https://git.openjdk.org/jdk/pull/21996


More information about the core-libs-dev mailing list