Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions junit-source-launcher/README.md
Original file line number Diff line number Diff line change
@@ -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());
}
}
```

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion junit-source-launcher/lib/DownloadRequiredModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
* https://www.eclipse.org/legal/epl-v20.html
*/

package example;
Copy link
Contributor

@mpkorstanje mpkorstanje Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While a bit more verbose using com.example.project would make this consistent with the other examples and provide just a bit more conventional context to make the package references elsewhere in the code instantly legible.


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());
}
}
13 changes: 13 additions & 0 deletions junit-source-launcher/src/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 1 addition & 2 deletions src/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ int build(Target target, Set<String> 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;
}
Expand Down
Loading