Skip to content

Commit 5819fbf

Browse files
fix: correct JUnit version logging for projects using ConsoleLauncher with vintage engine
ConsoleLauncher runs both JUnit 4 (via vintage engine) and JUnit 5 tests. The detection now correctly distinguishes between JUnit 5 projects (have junit-jupiter on classpath) and JUnit 4 projects using ConsoleLauncher as the runner. Previously, the injected console-standalone JAR falsely triggered "JUnit 5 detected" for all projects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent aad968d commit 5819fbf

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

codeflash/languages/java/test_runner.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,23 @@ def _run_tests_direct(
674674
java = _find_java_executable() or "java"
675675

676676
# Detect JUnit version from the classpath string.
677-
# Previously this probed the classpath via subprocess, but that's unreliable:
678-
# JUnit 5 projects often have JUnit 4 classes via junit-vintage-engine,
679-
# causing false JUnit 4 detection and failed test execution.
680-
# Instead, check if ConsoleLauncher (JUnit 5) is available on the classpath.
677+
# We check for junit-jupiter (the JUnit 5 test API) as the indicator of JUnit 5 tests.
678+
# Note: console-standalone and junit-platform are NOT reliable indicators because
679+
# we inject console-standalone ourselves in _get_test_classpath(), so it's always present.
680+
# ConsoleLauncher can run both JUnit 5 and JUnit 4 tests (via vintage engine),
681+
# so we prefer it when available and only fall back to JUnitCore for pure JUnit 4
682+
# projects without ConsoleLauncher on the classpath.
683+
has_junit5_tests = "junit-jupiter" in classpath
681684
has_console_launcher = "console-standalone" in classpath or "ConsoleLauncher" in classpath
682-
has_junit5 = "junit-jupiter" in classpath or "junit-platform" in classpath
683-
is_junit4 = not (has_console_launcher or has_junit5)
685+
# Use ConsoleLauncher if available (works for both JUnit 4 via vintage and JUnit 5).
686+
# Only use JUnitCore when ConsoleLauncher is not on the classpath at all.
687+
is_junit4 = not has_console_launcher
684688
if is_junit4:
685-
logger.debug("JUnit 4 detected (no JUnit 5 platform JARs on classpath), using JUnitCore")
689+
logger.debug("JUnit 4 project, no ConsoleLauncher available, using JUnitCore")
690+
elif has_junit5_tests:
691+
logger.debug("JUnit 5 project, using ConsoleLauncher")
686692
else:
687-
logger.debug("JUnit 5 detected on classpath, using ConsoleLauncher")
693+
logger.debug("JUnit 4 project, using ConsoleLauncher (via vintage engine)")
688694

689695
if is_junit4:
690696
# Use JUnit 4's JUnitCore runner

0 commit comments

Comments
 (0)