Skip to content

Commit 0200b14

Browse files
Merge pull request quarkusio#48269 from holly-cummins/improve-vscode-error-message
Handle VS Code case and improve exception message for IDE test launch failures
2 parents e19d60e + 1e694c6 commit 0200b14

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,16 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
162162
} catch (Exception | ServiceConfigurationError e) {
163163
boolean isEclipse = System.getProperty("sun.java.command") != null
164164
&& System.getProperty("sun.java.command").contains("JUnit5TestLoader");
165-
if (isEclipse) {
166-
// Tracked by https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257
165+
166+
// VS Code has the exact same java command and runner as Eclipse, but needs its own message
167+
boolean isVSCode = isEclipse && System.getProperty("java.class.path").contains("vscode");
168+
169+
if (isVSCode) {
170+
// Will need https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257 and a reconsume by VSCode
171+
Log.error(
172+
"Could not read configuration while evaluating whether to run a test. This is a known issue when running tests in the VS Code IDE. To work around the problem, run individual test methods.");
173+
} else if (isEclipse) {
174+
// Tracked by https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257; fixed in Eclipse 4.37
167175
Log.error(
168176
"Could not read configuration while evaluating whether to run a test. This is a known issue when running tests in the Eclipse IDE. To work around the problem, edit the run configuration and add `-uniqueId [engine:junit-jupiter]/[class:"
169177
+ context.getRequiredTestClass().getName()
@@ -177,8 +185,14 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
177185
Log.debug("Underlying exception: " + e);
178186
Log.debug("Thread Context Classloader: " + Thread.currentThread().getContextClassLoader());
179187
Log.debug("The class of the class we use for mapping is " + TestConfig.class.getClassLoader());
180-
throw new IllegalStateException("Non-viable test classloader, " + Thread.currentThread().getContextClassLoader()
181-
+ ". Is this a re-run of a failing test?");
188+
String message = isVSCode
189+
? "Could not execute test class because it was loaded with the wrong classloader by the VS Code test runner. Try running test methods individually instead."
190+
: isEclipse
191+
? "Could not execute test class because it was loaded with the wrong classloader by the Eclipse test runner. Try running test methods individually, or edit the run configuration and add `-uniqueId [engine:junit-jupiter]/[class:"
192+
+ context.getRequiredTestClass().getName()
193+
+ "]` in the program arguments. "
194+
: "Internal error: Test class was loaded with an unexpected classloader or the thread context classloader was incorrect.";
195+
throw new IllegalStateException(message, e);
182196
} finally {
183197
if (!isFlatClasspath) {
184198
Thread.currentThread().setContextClassLoader(original);

test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/CustomLauncherInterceptor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ private void initializeFacadeClassLoader() {
6767

6868
@Override
6969
public void launcherDiscoveryStarted(LauncherDiscoveryRequest request) {
70+
// If anything comes through this method for which there are non-null classloaders on the selectors, that will bypass our classloading
71+
// To check that case, the code would be something like this. We could detect and warn early, and possibly even filter that test out, but that's not necessarily a better UX than failing later
72+
// request.getSelectorsByType(ClassSelector.class).stream().map(ClassSelector::getClassLoader) ... and then check for non-emptiness on that field
73+
7074
// Do not do any classloading dance for prod mode tests;
7175
if (!isProductionModeTests()) {
7276
initializeFacadeClassLoader();

0 commit comments

Comments
 (0)