feat(run): run JUnit 5 tests of Maven modules without Maven (#5571)

Gutter Run / Debug of JUnit 5 tests in Maven modules now starts OpenIDEA's own JUnit Platform runner (java/junit-runner, built from the in-tree source and embedded by ide-sdk) on the language server's test classpath instead of mvn test, as IDEA runs Maven tests unless build/run actions are delegated to Maven. The runner reports TeamCity service messages to the existing test tree; Debug and Rerun Failed Tests reuse it. The launcher jar of the engine's version comes from the classpath, else from the engine's Maven/Gradle repository folder, else is downloaded once from Maven Central.

The runner JVM gets the module's Surefire configuration like IDEA's MavenJUnitPatcher: argLine (with @{...} late replacement), systemPropertyVariables / systemProperties, environmentVariables, workingDirectory, additionalClasspathElements and classpathDependencyExcludes, read from the cached effective POM (else the module POM); the console lists what was applied.

Settings › Build Tools › Maven › Run tests using: OpenIDEA (default) or Maven (the previous mvn test -Dtest=... path). JUnit 4-only, TestNG and Gradle tests keep their current runners.

Closes #5553

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-25 13:15:08 +08:00
1 джерело ae7a8e74c8
коміт 8c23c589ca
32 files changed
+1089 -48

No files matched your search

+37
Переглянути файл
@@ -29,6 +29,7 @@ const ipc = vi.hoisted(() => {
projectRoot: "/p",
classPaths: ["/p/app/target/classes"],
modulePaths: [],
pathListSeparator: ":",
javaHome: null,
javaExec: "java",
shortenCommandLine: null,
@@ -37,6 +38,15 @@ const ipc = vi.hoisted(() => {
hints: [],
}),
),
javaJunitRunner: vi.fn(() =>
ok({
classPaths: ["/p/app/target/test-classes", "/runner.jar"],
vmArgs: ["-Xmx1g", "-Dopenidea.fail=true"],
env: { TZ: "UTC" },
workingDirectory: "/p/app/work",
surefire: ["argLine", "systemPropertyVariables"],
}),
),
};
});
vi.mock("@/platform/ipc", async (original) => {
@@ -310,3 +320,30 @@ it("does not resolve or launch when saving fails", async () => {
expect(ipc.javaResolveLaunch).not.toHaveBeenCalled();
expect(ipc.runStart).not.toHaveBeenCalled();
});
it("gives the JUnit runner's JVM the module's Surefire configuration", async () => {
const report = vi.fn();
const junit: RunConfig = {
...config,
module: "app",
isTest: true,
args: ["-ea", "-cp", "${testClasspath}", "ai.openidea.junit.Runner", "a.MainTest#adds"],
env: { TZ: "Europe/Paris" },
};
const { resolved } = await prepareJavaLaunch(junit, { request: 1, signal: new AbortController().signal, report });
expect(ipc.javaJunitRunner).toHaveBeenCalledWith("app", ["/p/app/target/classes"]);
expect(resolved).toMatchObject({
args: [
"-Xmx1g",
"-Dopenidea.fail=true",
"-ea",
"-cp",
"/p/app/target/test-classes:/runner.jar",
"ai.openidea.junit.Runner",
"a.MainTest#adds",
],
env: { TZ: "Europe/Paris" },
cwd: "/p/app/work",
});
expect(report).toHaveBeenCalledWith("Applying the Surefire configuration: argLine, systemPropertyVariables\n");
});