Skip to content

Commit a4f782c

Browse files
authored
feat: junit 6 support (#1820)
* feat: support junit 6 import * test: update * test: update * feat: update * feat: updat code
1 parent bf16b31 commit a4f782c

File tree

18 files changed

+492
-79
lines changed

18 files changed

+492
-79
lines changed

java-extension/com.microsoft.java.test.plugin/META-INF/MANIFEST.MF

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,28 @@ Require-Bundle: org.eclipse.jdt.core,
2424
org.eclipse.jdt.junit.runtime,
2525
org.eclipse.jdt.junit4.runtime,
2626
org.eclipse.jdt.junit5.runtime,
27-
junit-jupiter-api;bundle-version="5.4.0",
28-
junit-jupiter-engine;bundle-version="5.4.0",
29-
junit-jupiter-migrationsupport;bundle-version="5.4.0",
30-
junit-jupiter-params;bundle-version="5.4.0",
31-
junit-vintage-engine;bundle-version="5.4.0",
32-
org.opentest4j;bundle-version="1.1.1",
33-
junit-platform-commons;bundle-version="1.4.0",
34-
junit-platform-engine;bundle-version="1.4.0",
35-
junit-platform-launcher;bundle-version="1.4.0",
36-
junit-platform-runner;bundle-version="1.4.0",
37-
junit-platform-suite-api;bundle-version="1.4.0",
38-
junit-platform-suite-commons;bundle-version="1.8.1",
39-
junit-platform-suite-engine;bundle-version="1.8.1",
27+
junit-jupiter-api;bundle-version="5.14.0",
28+
junit-jupiter-engine;bundle-version="5.14.0",
29+
junit-jupiter-migrationsupport;bundle-version="5.14.0",
30+
junit-jupiter-params;bundle-version="5.14.0",
31+
junit-vintage-engine;bundle-version="5.14.0",
32+
junit-platform-commons;bundle-version="1.14.1",
33+
junit-platform-engine;bundle-version="1.14.1",
34+
junit-platform-launcher;bundle-version="1.14.1",
35+
junit-platform-runner;bundle-version="1.14.1",
36+
junit-platform-suite-api;bundle-version="1.14.1",
37+
junit-platform-suite-commons;bundle-version="1.14.1",
38+
junit-platform-suite-engine;bundle-version="1.14.1",
39+
org.eclipse.jdt.junit6.runtime,
40+
junit-jupiter-api;bundle-version="6.0.1",
41+
junit-jupiter-engine;bundle-version="6.0.1",
42+
junit-jupiter-params;bundle-version="6.0.1",
43+
org.opentest4j;bundle-version="1.3.0",
44+
junit-platform-commons;bundle-version="6.0.1",
45+
junit-platform-engine;bundle-version="6.0.1",
46+
junit-platform-launcher;bundle-version="6.0.1",
47+
junit-platform-suite-api;bundle-version="6.0.1",
48+
junit-platform-suite-engine;bundle-version="6.0.1",
4049
org.apiguardian.api;bundle-version="1.0.0",
4150
org.apache.commons.lang3;bundle-version="3.1.0",
4251
com.google.gson;bundle-version="2.7.0",

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public Map<String, String> toValueMap() {
100100
final Map<String, String> valueMap = new HashMap<>();
101101
valueMap.put("testKind", testKind);
102102
valueMap.put("mainType", mainType);
103+
valueMap.put("projectName", project.getName());
103104
return valueMap;
104105
}
105106
}

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchConfigurationDelegate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ private void addTestItemArgs(List<String> arguments) throws CoreException {
147147
arguments.add("-test");
148148
final IMethod method = (IMethod) JavaCore.create(this.args.testNames[0]);
149149
String testName = method.getElementName();
150-
if (this.args.testKind == TestKind.JUnit5 && method.getParameters().length > 0) {
150+
if ((this.args.testKind == TestKind.JUnit5 || this.args.testKind == TestKind.JUnit6) &&
151+
method.getParameters().length > 0) {
151152
final ICompilationUnit unit = method.getCompilationUnit();
152153
if (unit == null) {
153154
throw new CoreException(new Status(IStatus.ERROR, JUnitPlugin.PLUGIN_ID, IStatus.ERROR,

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchConfigurationTemplate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class JUnitLaunchConfigurationTemplate {
2323
"<booleanAttribute key=\"org.eclipse.jdt.junit.KEEPRUNNING_ATTR\" value=\"false\"/>\n" +
2424
"<stringAttribute key=\"org.eclipse.jdt.junit.TEST_KIND\" value=\"${testKind}\"/>\n" +
2525
"<stringAttribute key=\"org.eclipse.jdt.launching.MAIN_TYPE\" value=\"${mainType}\"/>\n" +
26+
"<stringAttribute key=\"org.eclipse.jdt.launching.PROJECT_ATTR\" value=\"${projectName}\"/>\n" +
2627
"<stringAttribute key=\"org.eclipse.jdt.launching.VM_ARGUMENTS\" value=\"-ea\"/>\n" +
2728
"</launchConfiguration>\n";
2829
//@formatter:on

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/launchers/JUnitLaunchUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
public class JUnitLaunchUtils {
4848

4949
private static final String TESTNG_LOADER = "com.microsoft.java.test.loader.testng";
50+
private static final String JUNIT6_LOADER = "org.eclipse.jdt.junit.loader.junit6";
5051
private static final String JUNIT5_LOADER = "org.eclipse.jdt.junit.loader.junit5";
5152
private static final String JUNIT4_LOADER = "org.eclipse.jdt.junit.loader.junit4";
5253

@@ -205,6 +206,8 @@ private static String getEclipseTestKind(TestKind testKind) {
205206
return JUNIT4_LOADER;
206207
case JUnit5:
207208
return JUNIT5_LOADER;
209+
case JUnit6:
210+
return JUNIT6_LOADER;
208211
case TestNG:
209212
return TESTNG_LOADER;
210213
default:

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/model/TestKind.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ public enum TestKind {
2424
@SerializedName("2")
2525
TestNG(2),
2626

27+
@SerializedName("3")
28+
JUnit6(3),
29+
2730
@SerializedName("100")
2831
None(100);
2932

3033
private int value;
3134

3235
public static TestKind fromString(String s) {
33-
switch(s) {
36+
switch (s) {
3437
case "Unknown":
3538
return None;
3639
case "JUnit 4":
3740
return JUnit;
3841
case "JUnit 5":
3942
return JUnit5;
43+
case "JUnit 6":
44+
return JUnit6;
4045
case "TestNG":
4146
return TestNG;
4247
default:
@@ -53,6 +58,8 @@ public String toString() {
5358
return "JUnit 4";
5459
case JUnit5:
5560
return "JUnit 5";
61+
case JUnit6:
62+
return "JUnit 6";
5663
case TestNG:
5764
return "TestNG";
5865
default:
@@ -64,7 +71,7 @@ public int getValue() {
6471
return this.value;
6572
}
6673

67-
private TestKind(int value){
74+
private TestKind(int value) {
6875
this.value = value;
6976
}
7077
}

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/provider/TestKindProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.eclipse.jdt.core.IJavaProject;
1818
import org.eclipse.jdt.core.JavaModelException;
19+
import org.eclipse.jdt.internal.junit.util.CoreTestSearchEngine;
1920

2021
import java.util.HashMap;
2122
import java.util.LinkedList;
@@ -44,7 +45,10 @@ public static List<TestKind> getTestKindsFromCache(IJavaProject javaProject) {
4445
private static List<TestKind> getTestKinds(IJavaProject javaProject) {
4546
final List<TestKind> result = new LinkedList<>();
4647
try {
47-
if (javaProject.findType(JUNIT5_TEST) != null) {
48+
// Check for JUnit 6 first using Eclipse JDT's built-in detection
49+
if (CoreTestSearchEngine.hasJUnit6TestAnnotation(javaProject)) {
50+
result.add(TestKind.JUnit6);
51+
} else if (CoreTestSearchEngine.hasJUnit5TestAnnotation(javaProject)) {
4852
result.add(TestKind.JUnit5);
4953
}
5054

0 commit comments

Comments
 (0)