Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,16 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
} catch (Exception | ServiceConfigurationError e) {
boolean isEclipse = System.getProperty("sun.java.command") != null
&& System.getProperty("sun.java.command").contains("JUnit5TestLoader");
if (isEclipse) {
// Tracked by https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257

// VS Code has the exact same java command and runner as Eclipse, but needs its own message
boolean isVSCode = isEclipse && System.getProperty("java.class.path").contains("vscode");

if (isVSCode) {
// Will need https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257 and a reconsume by VSCode
Log.error(
"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.");
} else if (isEclipse) {
// Tracked by https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257; fixed in Eclipse 4.37
Log.error(
"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:"
+ context.getRequiredTestClass().getName()
Expand All @@ -177,8 +185,14 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
Log.debug("Underlying exception: " + e);
Log.debug("Thread Context Classloader: " + Thread.currentThread().getContextClassLoader());
Log.debug("The class of the class we use for mapping is " + TestConfig.class.getClassLoader());
throw new IllegalStateException("Non-viable test classloader, " + Thread.currentThread().getContextClassLoader()
+ ". Is this a re-run of a failing test?");
String message = isVSCode
? "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."
: isEclipse
? "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:"
+ context.getRequiredTestClass().getName()
+ "]` in the program arguments. "
: "Internal error: Test class was loaded with an unexpected classloader or the thread context classloader was incorrect.";
throw new IllegalStateException(message, e);
} finally {
if (!isFlatClasspath) {
Thread.currentThread().setContextClassLoader(original);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private void initializeFacadeClassLoader() {

@Override
public void launcherDiscoveryStarted(LauncherDiscoveryRequest request) {
// If anything comes through this method for which there are non-null classloaders on the selectors, that will bypass our classloading
// 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
// request.getSelectorsByType(ClassSelector.class).stream().map(ClassSelector::getClassLoader) ... and then check for non-emptiness on that field

// Do not do any classloading dance for prod mode tests;
if (!isProductionModeTests()) {
initializeFacadeClassLoader();
Expand Down
Loading