diff --git a/junit-source-launcher/README.md b/junit-source-launcher/README.md index ebec5028..a15f587f 100644 --- a/junit-source-launcher/README.md +++ b/junit-source-launcher/README.md @@ -1,18 +1,22 @@ # junit-source-launcher Starting with Java 25 it is possible to write minimal source code test programs using the `org.junit.start` module. -For example, take a look at the [HelloTests.java](src/HelloTests.java) file reading: +For example, take a look at the [HelloTests.java](src/example/HelloTests.java) file reading: ```java +package example; + import module org.junit.start; -void main() { - JUnit.run(); -} +class HelloTests { + void main() { + JUnit.run(); + } -@Test -void stringLength() { - Assertions.assertEquals(11, "Hello JUnit".length()); + @Test + void stringLength() { + Assertions.assertEquals(11, "Hello JUnit".length()); + } } ``` @@ -25,7 +29,7 @@ java lib/DownloadRequiredModules.java With all required modular JAR files available in a local `lib/` directory, the following Java command will discover and execute tests using the JUnit Platform. ```shell -java --module-path lib --add-modules org.junit.start src/HelloTests.java +java --module-path lib src/example/HelloTests.java ``` It will also print the result tree to the console. diff --git a/junit-source-launcher/lib/DownloadRequiredModules.java b/junit-source-launcher/lib/DownloadRequiredModules.java index 90e50feb..0682cf83 100644 --- a/junit-source-launcher/lib/DownloadRequiredModules.java +++ b/junit-source-launcher/lib/DownloadRequiredModules.java @@ -38,7 +38,7 @@ void main() throws Exception { // Ensure being launched inside expected working directory - var program = Path.of("src", "HelloTests.java"); + var program = Path.of("src", "example", "HelloTests.java"); if (!Files.exists(program)) { throw new AssertionError("Expected %s in current working directory".formatted(program)); } diff --git a/junit-source-launcher/src/HelloTests.java b/junit-source-launcher/src/example/HelloTests.java similarity index 68% rename from junit-source-launcher/src/HelloTests.java rename to junit-source-launcher/src/example/HelloTests.java index 769de9a7..91d5760b 100644 --- a/junit-source-launcher/src/HelloTests.java +++ b/junit-source-launcher/src/example/HelloTests.java @@ -8,13 +8,17 @@ * https://www.eclipse.org/legal/epl-v20.html */ +package example; + import module org.junit.start; -void main() { - JUnit.run(); -} +class HelloTests { + void main() { + JUnit.run(); + } -@Test -void stringLength() { - Assertions.assertEquals(11, "Hello JUnit".length()); + @Test + void stringLength() { + Assertions.assertEquals(11, "Hello JUnit".length()); + } } diff --git a/junit-source-launcher/src/module-info.java b/junit-source-launcher/src/module-info.java new file mode 100644 index 00000000..bd21a47c --- /dev/null +++ b/junit-source-launcher/src/module-info.java @@ -0,0 +1,13 @@ +/* + * Copyright 2015-2026 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +open module example { + requires org.junit.start; +} diff --git a/src/Builder.java b/src/Builder.java index ecd5604c..83d4c2bf 100644 --- a/src/Builder.java +++ b/src/Builder.java @@ -82,8 +82,7 @@ int build(Target target, Set excludedProjects) { runProject(excludedProjects, "junit-source-launcher", "java", "--module-path", "lib", - "--add-modules", "org.junit.start", - "src/HelloTests.java"); + "src/example/HelloTests.java"); System.out.printf("%n%n%n|%n| Done. Build exits with status = %d.%n|%n", status); return status; }