The jpackage test lib provides limited capabilities similar to JUnit for running parametrized tests [1]. It has some annoying shortcomings that are fairly easy to fix, which makes writing jpackage tests more convenient.
The list is:
- Can't configure multiple args with @jdk.jpackage.test.Annotations.Parameter annotation. It can configure only one. The workaround is var args, but it allows passing only strings or objects of the same type. The following will not work:
@Parameter("foo", "10")
void test(String a, int, b)
Workaround:
@Parameter("foo", "10")
void test(String ... args) {
String a = args[0]; // "foo"
int b = Integer.parseInt(args[1]); // 10
}
- Limited support for var arg constructors:
class Test {
Test(Path ... extra) // << Will work
Test(Path v, Path ... extra) // << Will NOT work
Test(int a, String ... extra) // << Will NOT work
}
- Doesn't handle well ctor arguments with null-s. It can't always deduce a constructor to call if there are a few.
- Only the first method with @Parameters annotation will be used in the test [2]. No good reason to ignore others.
- The only way to supply parameters to a test function is with @Paramater annotation. It has limited capabilities (only strings can be used as values) and doesn't scale well (adding more than a few @Paramater annotations to a method is ugly). It would be handy to have an alternative to @Parameters annotation but for methods. Something like:
@ParameterSupplier("inputForTest")
public void test(String arg, LocalDate ... dates) {
...
}
public static Collection<Object[]> inputForTest() {
return List.of(new Object[][] {
{"foo"},
{"foo", LocalDate.parse("2007-12-03")},
{"foo", LocalDate.parse("2007-12-03"), LocalDate.parse("2027-12-03")},
});
}
- It would be handy if annotations supplying test data get activated based on the current OS (linux, macos, windows). Something like:
@Test
@Parameter(value="only on windows", ifOS=OperatingSystem.WINDOWS)
@Parameter(value="only on windows and linux", ifOS={OperatingSystem.WINDOWS,OperatingSystem.LINUX})
@Parameter(value="not on linux", ifNotOS=OperatingSystem.LINUX)
public void test(String arg) {
}
- If the test class has a static test case method and a method annotated with @jdk.jpackage.test.Annotations.Parameters this test case will be executed with every test instance. It should be executed only once with no test instance. This is not an enhancement, but a bug.
- The test case description contains a short test class name and doesn't contain a test class package name. It makes it difficult to cherry-pick test cases from the test log for rerunning:
%> java ... jdk.jpackage.test.Main --jpt-run=jdk.jpackage.tests.BasicTest,SimplePackageTest
SimplePackageTest.test; workDir=[.\SimplePackageTest\test]
...
BasicTest.testApp(Hello); workDir=[.\BasicTest\testApp.6cba4700]
BasicTest.testAtFile; workDir=[.\BasicTest\testAtFile]
...
But the output should be:
SimplePackageTest.test; workDir=[.\SimplePackageTest\test]
...
jdk.jpackage.tests.BasicTest.testApp(Hello); workDir=[.\BasicTest\testApp.6cba4700]
jdk.jpackage.tests.BasicTest.testAtFile; workDir=[.\BasicTest\testAtFile]
...
[1] https://github.com/openjdk/jdk/blob/master/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java
[2] https://github.com/openjdk/jdk/blob/52c0b09b62ca82f7e0cbe910cb92243131f06765/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java#L340
The list is:
- Can't configure multiple args with @jdk.jpackage.test.Annotations.Parameter annotation. It can configure only one. The workaround is var args, but it allows passing only strings or objects of the same type. The following will not work:
@Parameter("foo", "10")
void test(String a, int, b)
Workaround:
@Parameter("foo", "10")
void test(String ... args) {
String a = args[0]; // "foo"
int b = Integer.parseInt(args[1]); // 10
}
- Limited support for var arg constructors:
class Test {
Test(Path ... extra) // << Will work
Test(Path v, Path ... extra) // << Will NOT work
Test(int a, String ... extra) // << Will NOT work
}
- Doesn't handle well ctor arguments with null-s. It can't always deduce a constructor to call if there are a few.
- Only the first method with @Parameters annotation will be used in the test [2]. No good reason to ignore others.
- The only way to supply parameters to a test function is with @Paramater annotation. It has limited capabilities (only strings can be used as values) and doesn't scale well (adding more than a few @Paramater annotations to a method is ugly). It would be handy to have an alternative to @Parameters annotation but for methods. Something like:
@ParameterSupplier("inputForTest")
public void test(String arg, LocalDate ... dates) {
...
}
public static Collection<Object[]> inputForTest() {
return List.of(new Object[][] {
{"foo"},
{"foo", LocalDate.parse("2007-12-03")},
{"foo", LocalDate.parse("2007-12-03"), LocalDate.parse("2027-12-03")},
});
}
- It would be handy if annotations supplying test data get activated based on the current OS (linux, macos, windows). Something like:
@Test
@Parameter(value="only on windows", ifOS=OperatingSystem.WINDOWS)
@Parameter(value="only on windows and linux", ifOS={OperatingSystem.WINDOWS,OperatingSystem.LINUX})
@Parameter(value="not on linux", ifNotOS=OperatingSystem.LINUX)
public void test(String arg) {
}
- If the test class has a static test case method and a method annotated with @jdk.jpackage.test.Annotations.Parameters this test case will be executed with every test instance. It should be executed only once with no test instance. This is not an enhancement, but a bug.
- The test case description contains a short test class name and doesn't contain a test class package name. It makes it difficult to cherry-pick test cases from the test log for rerunning:
%> java ... jdk.jpackage.test.Main --jpt-run=jdk.jpackage.tests.BasicTest,SimplePackageTest
SimplePackageTest.test; workDir=[.\SimplePackageTest\test]
...
BasicTest.testApp(Hello); workDir=[.\BasicTest\testApp.6cba4700]
BasicTest.testAtFile; workDir=[.\BasicTest\testAtFile]
...
But the output should be:
SimplePackageTest.test; workDir=[.\SimplePackageTest\test]
...
jdk.jpackage.tests.BasicTest.testApp(Hello); workDir=[.\BasicTest\testApp.6cba4700]
jdk.jpackage.tests.BasicTest.testAtFile; workDir=[.\BasicTest\testAtFile]
...
[1] https://github.com/openjdk/jdk/blob/master/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java
[2] https://github.com/openjdk/jdk/blob/52c0b09b62ca82f7e0cbe910cb92243131f06765/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java#L340
- relates to
-
JDK-8344322 Improve capabilities of jpackage test lib to validate error output of jpackage
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk/41a627b7
-
Review(master) openjdk/jdk/21996