[junit]: IDEA-386776 IJ-CR-195055 adds an error message for JUnit 6 fallback

(cherry picked from commit 0d40a6b7c09d0d9a80721cfe64a2189298d680f9)

IJ-CR-195055

GitOrigin-RevId: d5adf84d5e3fa2577d8d8df1191f984240db9e3c
This commit is contained in:
Aleksey Dobrynin
2026-03-16 11:19:22 +00:00
committed by intellij-monorepo-bot
parent 229e495b63
commit 3275c3740b
2 changed files with 15 additions and 2 deletions
@@ -111,7 +111,9 @@ public class JUnitVersionSwitchingIntegrationTest extends AbstractTestFrameworkC
ProcessOutput output = doStartTestsProcess(configuration,
params -> replaceJUnitVersion(params, JUnitStarter.JUNIT6_PARAMETER));
assertEmpty(output.err);
assertTrue("stderr must contain the 'JUnit 6 cannot be used with the current test runtime classpath. Falling back to JUnit 5.' error message",
ContainerUtil.exists(output.err, s -> s.contains("JUnit 6 cannot be used with the current test runtime classpath. Falling back to JUnit 5.")));
assertTrue(output.sys.toString().contains("-junit6"));
assertTrue("Test output must report that JUnit6 classes are absent (junit6.classes.present=false)",
@@ -152,7 +154,9 @@ public class JUnitVersionSwitchingIntegrationTest extends AbstractTestFrameworkC
assertNotNull(configuration);
ProcessOutput output = doStartTestsProcess(configuration, params -> replaceJUnitVersion(params, JUnitStarter.JUNIT6_PARAMETER));
assertEmpty(output.err);
assertTrue("stderr must contain the 'JUnit 6 cannot be used with the current test runtime classpath. Falling back to JUnit 5.' error message",
ContainerUtil.exists(output.err, s -> s.contains("JUnit 6 cannot be used with the current test runtime classpath. Falling back to JUnit 5.")));
assertTrue(output.sys.toString().contains("-junit6"));
assertTrue("Test output must report that JUnit6 classes are absent (junit6.classes.present=false)",
@@ -157,6 +157,15 @@ public final class JUnitStarter {
switch (runner) {
case JUNIT6:
if (JUnitRunner.JUNIT6.check()) return JUnitRunner.JUNIT6;
if (JUnitRunner.JUNIT5.check()) {
System.err.println("JUnit 6 cannot be used with the current test runtime classpath. Falling back to JUnit 5.");
System.err.println("If you expected JUnit 6, please check the test runtime dependencies.");
System.err.flush();
return JUnitRunner.JUNIT5;
}
System.err.println("!!! JUnit Platform is not available on the classpath");
System.err.flush();
System.exit(-3);
case JUNIT5:
if (JUnitRunner.JUNIT5.check()) return JUnitRunner.JUNIT5;
System.err.println("!!! JUnit Platform is not available on the classpath");