Skip to content

Commit 54cb5ec

Browse files
committed
Support JUnit 6 plug-in test launches
Fixes: #2108
1 parent 5878cb4 commit 54cb5ec

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ public static void main(String[] args) {
102102
RemotePluginTestRunner testRunner = new RemotePluginTestRunner();
103103
testRunner.init(args);
104104
ClassLoader currentTCCL = Thread.currentThread().getContextClassLoader();
105-
if (isJUnit5(args)) {
105+
boolean isJUnitJupiter = isJUnit5(args) || isJUnit6(args);
106+
if (isJUnitJupiter) {
106107
//change the classloader so that the test classes in testplugin are discoverable
107108
//by junit5 framework see bug 520811
108109
Thread.currentThread().setContextClassLoader(createJUnit5PluginClassLoader(testRunner.getTestPluginName()));
109110
}
110111
testRunner.run();
111-
if (isJUnit5(args)) {
112+
if (isJUnitJupiter) {
112113
Thread.currentThread().setContextClassLoader(currentTCCL);
113114
}
114115
}
@@ -206,6 +207,11 @@ private static boolean isJUnit5(String[] args) {
206207
return indexOf(args, "-runasjunit5"::equalsIgnoreCase) > -1 || indexOf(args, "org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader"::equals) > -1;
207208
}
208209

210+
@SuppressWarnings("nls")
211+
private static boolean isJUnit6(String[] args) {
212+
return indexOf(args, "-runasjunit6"::equalsIgnoreCase) > -1 || indexOf(args, "org.eclipse.jdt.internal.junit6.runner.JUnit6TestLoader"::equals) > -1;
213+
}
214+
209215
public void readPluginArgs(String[] args) {
210216
fTestPluginName = getArgumentValue(args, "-testpluginname"); //$NON-NLS-1$
211217
String loaderPlugin = getArgumentValue(args, "-loaderpluginname"); //$NON-NLS-1$

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/JUnitLaunchRequirements.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class JUnitLaunchRequirements {
5353
private static final String PDE_JUNIT_RUNTIME = "org.eclipse.pde.junit.runtime"; //$NON-NLS-1$
5454
private static final String JUNIT4_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit4.runtime"; //$NON-NLS-1$
5555
private static final String JUNIT5_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit5.runtime"; //$NON-NLS-1$
56+
private static final String JUNIT6_JDT_RUNTIME_PLUGIN = "org.eclipse.jdt.junit6.runtime"; //$NON-NLS-1$
5657

5758
public static void addRequiredJunitRuntimePlugins(ILaunchConfiguration configuration, Map<String, List<IPluginModelBase>> collectedModels, Map<IPluginModelBase, String> startLevelMap) throws CoreException {
5859
Collection<IPluginModelBase> runtimeBundles = getEclipseJunitRuntimePlugins(configuration, collectedModels, startLevelMap);
@@ -150,6 +151,9 @@ public static Collection<String> getRequiredJunitRuntimeEclipsePlugins(ILaunchCo
150151
case org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID -> {
151152
return List.of(PDE_JUNIT_RUNTIME, JUNIT5_JDT_RUNTIME_PLUGIN);
152153
}
154+
case org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT6_TEST_KIND_ID -> {
155+
return List.of(PDE_JUNIT_RUNTIME, JUNIT6_JDT_RUNTIME_PLUGIN);
156+
}
153157
default -> throw new IllegalArgumentException("Unsupported junit test kind: " + testKind.getId()); //$NON-NLS-1$
154158
}
155159
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,12 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
518518
fAllBundles = fModels.keySet().stream().collect(Collectors.groupingBy(m -> m.getPluginBase().getId(), LinkedHashMap::new, Collectors.toCollection(ArrayList::new)));
519519
launchMode = launch.getLaunchMode();
520520

521+
System.out.println("Before");
522+
fModels.keySet().stream().map(IPluginModelBase::getBundleDescription).filter(d -> d.getSymbolicName().startsWith("junit")).forEach(System.out::println);
521523
// implicitly add the plug-ins required for JUnit testing if necessary
522524
JUnitLaunchRequirements.addRequiredJunitRuntimePlugins(configuration, fAllBundles, fModels);
525+
System.out.println("After");
526+
fModels.keySet().stream().map(IPluginModelBase::getBundleDescription).filter(d -> d.getSymbolicName().startsWith("junit")).forEach(System.out::println);
523527

524528
String attribute = launch.getAttribute(PDE_JUNIT_SHOW_COMMAND);
525529
boolean isShowCommand = false;

0 commit comments

Comments
 (0)