From 3275c3740b433bb1123ebb7aa6df2c866b692eff Mon Sep 17 00:00:00 2001 From: Aleksey Dobrynin Date: Tue, 10 Mar 2026 13:25:19 +0100 Subject: [PATCH] [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 --- .../junit5/JUnitVersionSwitchingIntegrationTest.java | 8 ++++++-- .../junit_rt/src/com/intellij/rt/junit/JUnitStarter.java | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnitVersionSwitchingIntegrationTest.java b/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnitVersionSwitchingIntegrationTest.java index 6e5ecd6a3296..e8102981f2f0 100644 --- a/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnitVersionSwitchingIntegrationTest.java +++ b/plugins/junit5_rt_tests/test/com/intellij/junit5/JUnitVersionSwitchingIntegrationTest.java @@ -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)", diff --git a/plugins/junit_rt/src/com/intellij/rt/junit/JUnitStarter.java b/plugins/junit_rt/src/com/intellij/rt/junit/JUnitStarter.java index 2d54be8d91f7..465e3814ebf6 100644 --- a/plugins/junit_rt/src/com/intellij/rt/junit/JUnitStarter.java +++ b/plugins/junit_rt/src/com/intellij/rt/junit/JUnitStarter.java @@ -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");