Skip to content

Commit a2b45e2

Browse files
trancexpressiloveeclipse
authored andcommitted
Copy JUnit 5 tests for JUnit 6 tests
Fixes #2111
1 parent 7185660 commit a2b45e2

File tree

24 files changed

+362
-21
lines changed

24 files changed

+362
-21
lines changed

ui/org.eclipse.pde.junit.runtime.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.29.0",
1919
org.eclipse.pde.ui.tests;bundle-version="3.11.500",
2020
org.eclipse.jdt.junit4.runtime;bundle-version="[1.3.0,2.0.0)",
2121
org.eclipse.jdt.junit5.runtime;bundle-version="[1.1.0,2.0.0)",
22+
org.eclipse.jdt.junit6.runtime;bundle-version="[1.0.0,2.0.0)",
2223
org.eclipse.pde.junit.runtime;bundle-version="[3.8.0,4.0.0)"
2324
Import-Package: org.assertj.core.api;version="3.14.0",
2425
org.junit,

ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitExecutionTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Julian Honnen
2+
* Copyright (c) 2019, 2025 Julian Honnen
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -77,7 +77,10 @@ public static void setupProjects() throws Exception {
7777

7878
@Parameters(name = "{0}")
7979
public static Object[][] parameters() {
80-
return new Object[][] { { "JUnit5", getJProject("verification.tests.junit5") },
80+
return new Object[][] {
81+
{ "JUnit6", getJProject("verification.tests.junit6") },
82+
{ "JUnit6 Fragment", getJProject("verification.tests.junit6.fragment") },
83+
{ "JUnit5", getJProject("verification.tests.junit5") },
8184
{ "JUnit5 Fragment", getJProject("verification.tests.junit5.fragment") },
8285
{ "JUnit4", getJProject("verification.tests.junit4") },
8386
{ "JUnit4 Fragment", getJProject("verification.tests.junit4.fragment") },
@@ -101,25 +104,25 @@ public void executeType() throws Exception {
101104
IType testClass = findType(project, "Test1");
102105
ITestRunSession session = TestExecutionUtil.runTest(testClass);
103106

104-
assertThat(session.getChildren()).hasSize(1);
105107
assertSuccessful(session);
108+
assertThat(session.getChildren()).hasSize(1);
106109
}
107110

108111
@Test
109112
public void executePackage() throws Exception {
110113
IPackageFragment testPackage = findType(project, "Test1").getPackageFragment();
111114
ITestRunSession session = TestExecutionUtil.runTest(testPackage);
112115

113-
assertThat(session.getChildren()).hasSize(2);
114116
assertSuccessful(session);
117+
assertThat(session.getChildren()).hasSize(2);
115118
}
116119

117120
@Test
118121
public void executeProject() throws Exception {
119122
ITestRunSession session = TestExecutionUtil.runTest(project);
120123

121-
assertThat(session.getChildren()).hasSize(2);
122124
assertSuccessful(session);
125+
assertThat(session.getChildren()).hasSize(2);
123126
}
124127

125128
@Test
@@ -128,8 +131,8 @@ public void executeMethod() throws Exception {
128131
Assume.assumeTrue(testMethod.exists());
129132
ITestRunSession session = TestExecutionUtil.runTest(testMethod);
130133

131-
assertThat(session.getChildren()).hasSize(1);
132134
assertSuccessful(session);
135+
assertThat(session.getChildren()).hasSize(1);
133136
}
134137

135138
static void assertSuccessful(ITestRunSession session) {

ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitRuntimeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Julian Honnen
2+
* Copyright (c) 2019, 2025 Julian Honnen
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,7 +18,7 @@
1818
import org.junit.runners.Suite.SuiteClasses;
1919

2020
@RunWith(Suite.class)
21-
@SuiteClasses({ JUnitExecutionTest.class, JUnit5SuiteExecutionTest.class })
21+
@SuiteClasses({ JUnitExecutionTest.class, JUnitSuiteExecutionTest.class })
2222
public class JUnitRuntimeTests {
2323

2424
}

ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnit5SuiteExecutionTest.java renamed to ui/org.eclipse.pde.junit.runtime.tests/src/org/eclipse/pde/junit/runtime/tests/JUnitSuiteExecutionTest.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2022 Julian Honnen
2+
* Copyright (c) 2021, 2022, 2025 Julian Honnen
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
1717
import static org.eclipse.pde.junit.runtime.tests.JUnitExecutionTest.findType;
18+
import static org.eclipse.pde.junit.runtime.tests.JUnitExecutionTest.getJProject;
1819

1920
import java.util.StringJoiner;
2021

@@ -30,36 +31,55 @@
3031
import org.junit.ClassRule;
3132
import org.junit.Test;
3233
import org.junit.rules.TestRule;
34+
import org.junit.runner.RunWith;
35+
import org.junit.runners.Parameterized;
36+
import org.junit.runners.Parameterized.Parameter;
37+
import org.junit.runners.Parameterized.Parameters;
3338

34-
public class JUnit5SuiteExecutionTest {
39+
@RunWith(Parameterized.class)
40+
public class JUnitSuiteExecutionTest {
3541

3642
@ClassRule
3743
public static final TestRule CLEAR_WORKSPACE = ProjectUtils.DELETE_ALL_WORKSPACE_PROJECTS_BEFORE_AND_AFTER;
3844

39-
private static IJavaProject project;
40-
4145
@BeforeClass
4246
public static void setupProjects() throws Exception {
4347
Assert.assertNotNull("junit-platform-suite-engine bundle missing", Platform.getBundle("junit-platform-suite-engine"));
4448
Assert.assertNotNull("org.eclipse.jdt.junit5.runtime bundle missing", Platform.getBundle("org.eclipse.jdt.junit5.runtime"));
49+
Assert.assertNotNull("org.eclipse.jdt.junit6.runtime bundle missing", Platform.getBundle("org.eclipse.jdt.junit6.runtime"));
4550

4651
JUnitExecutionTest.setupProjects();
47-
project = JUnitExecutionTest.getJProject("verification.tests.junit5.suite");
4852
}
4953

54+
@Parameters(name = "{0}")
55+
public static Object[][] parameters() {
56+
return new Object[][] {
57+
{ "JUnit6", getJProject("verification.tests.junit6.suite"), "verification.tests.junit6" },
58+
{ "JUnit5", getJProject("verification.tests.junit5.suite"), "verification.tests.junit5" },
59+
};
60+
}
61+
62+
@Parameter(0)
63+
public String testCaseName; // Just for display
64+
@Parameter(1)
65+
public IJavaProject project;
66+
@Parameter(2)
67+
public String packageName;
68+
5069
@Test
5170
public void executeSuite() throws Exception {
5271
ITestRunSession session = TestExecutionUtil.runTest(findType(project, "TestSuite"));
5372
JUnitExecutionTest.assertSuccessful(session);
54-
Assert.assertEquals("""
55-
verification.tests.junit5.suite.TestSuite
73+
String expected = String.format("""
74+
%1$s.suite.TestSuite
5675
JUnit Jupiter
57-
verification.tests.junit5.Test1
58-
test1(verification.tests.junit5.Test1)
59-
test2(verification.tests.junit5.Test1)
60-
verification.tests.junit5.Test2
61-
test(verification.tests.junit5.Test2)
62-
""".strip(), toString(session).strip());
76+
%1$s.Test1
77+
test1(%1$s.Test1)
78+
test2(%1$s.Test1)
79+
%1$s.Test2
80+
test(%1$s.Test2)
81+
""", packageName);
82+
Assert.assertEquals(expected.strip(), toString(session).strip());
6383
}
6484

6585
@Test
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src">
6+
<attributes>
7+
<attribute name="test" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="output" path="bin"/>
11+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>verification.tests.junit6.fragment</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Fragment
4+
Bundle-SymbolicName: verification.tests.junit6.fragment
5+
Bundle-Version: 1.0.0.qualifier
6+
Fragment-Host: verification.tests.junit5;bundle-version="1.0.0.qualifier"
7+
Automatic-Module-Name: verification.tests.junit6.fragment
8+
Bundle-RequiredExecutionEnvironment: JavaSE-17
9+
Export-Package: verification.tests.junit6.fragment
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Julian Honnen
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Julian Honnen <[email protected]> - initial API and implementation
13+
*******************************************************************************/
14+
package verification.tests.junit6.fragment;
15+
16+
import org.junit.jupiter.api.Test;
17+
18+
class Test1 {
19+
20+
@Test
21+
void test1() {
22+
23+
}
24+
25+
@Test
26+
void test2() {
27+
28+
}
29+
30+
}

0 commit comments

Comments
 (0)