-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
JUnit 5 is properly fitted with modules but junit-platform-console-standalone-1.13.4.jar
does not include a module-info.class
. This is probably due to Java's limitation of not allowing more than one such file in a .jar
file, however, it would be reasonable and feasible to have just one: that of the API.
All of the following code assumes Java 25 (or at least Java 23+).
Ideal
The ideal, reasonable-looking minimal tester file for me would look like this.
import module org.junit.jupiter.api;
@Test
void test() {
assertEquals(4, 2+2);
}
It would be compiled as javac -p junit-platform-console-standalone-VSN.jar MinimalTest.java
and then run as java -jar junit5_modules.jar execute -cp . -c MinimalTest
.
What works in a mock implementation
Due to limitations, the file needs some boilerplate which makes it more annoying for beginners to use.
import module org.junit.jupiter.api;
// bloat: modules provide imports, just not static ones
import static org.junit.jupiter.api.Assertions.*;
@Test
void test() {
assertEquals(4, 2+2);
}
// bloat: compact source files must have this
// or it could be a regular source file with a different sort of bloat
void main() {}
Compilation also requires an extra option: javac --add-modules org.junit.jupiter.api -p junit-platform-console-standalone-VSN.jar MinimalTest.java
The module-info.class
file also has to be inserted into junit-platform-console-standalone-VSN.jar
(considered as a zip
).
Deliverables
- The
junit-platform-console-standalone-***.jar
becomes usable as aorg.junit.jupiter.api
module.