Skip to content

Commit fe7432b

Browse files
committed
Copied JUnit 5 tests for JUnit 6 tests
Fixes: #2111
1 parent ef2d9f1 commit fe7432b

File tree

24 files changed

+421
-4
lines changed

24 files changed

+421
-4
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,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 org.eclipse.pde.junit.runtime.tests;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.eclipse.pde.junit.runtime.tests.JUnitExecutionTest.findType;
18+
19+
import java.util.StringJoiner;
20+
21+
import org.eclipse.core.runtime.Platform;
22+
import org.eclipse.jdt.core.IJavaProject;
23+
import org.eclipse.jdt.internal.junit.model.TestElement;
24+
import org.eclipse.jdt.junit.model.ITestElement;
25+
import org.eclipse.jdt.junit.model.ITestElementContainer;
26+
import org.eclipse.jdt.junit.model.ITestRunSession;
27+
import org.eclipse.pde.ui.tests.util.ProjectUtils;
28+
import org.junit.Assert;
29+
import org.junit.BeforeClass;
30+
import org.junit.ClassRule;
31+
import org.junit.Test;
32+
import org.junit.rules.TestRule;
33+
34+
public class JUnit6SuiteExecutionTest {
35+
36+
@ClassRule
37+
public static final TestRule CLEAR_WORKSPACE = ProjectUtils.DELETE_ALL_WORKSPACE_PROJECTS_BEFORE_AND_AFTER;
38+
39+
private static IJavaProject project;
40+
41+
@BeforeClass
42+
public static void setupProjects() throws Exception {
43+
Assert.assertNotNull("junit-platform-suite-engine bundle missing", Platform.getBundle("junit-platform-suite-engine"));
44+
Assert.assertNotNull("org.eclipse.jdt.junit6.runtime bundle missing", Platform.getBundle("org.eclipse.jdt.junit6.runtime"));
45+
46+
JUnitExecutionTest.setupProjects();
47+
project = JUnitExecutionTest.getJProject("verification.tests.junit6.suite");
48+
}
49+
50+
@Test
51+
public void executeSuite() throws Exception {
52+
ITestRunSession session = TestExecutionUtil.runTest(findType(project, "TestSuite"));
53+
JUnitExecutionTest.assertSuccessful(session);
54+
Assert.assertEquals("""
55+
verification.tests.junit6.suite.TestSuite
56+
JUnit Jupiter
57+
verification.tests.junit6.Test1
58+
test1(verification.tests.junit6.Test1)
59+
test2(verification.tests.junit6.Test1)
60+
verification.tests.junit6.Test2
61+
test(verification.tests.junit6.Test2)
62+
""".strip(), toString(session).strip());
63+
}
64+
65+
@Test
66+
public void executePackage() throws Exception {
67+
ITestRunSession session = TestExecutionUtil.runTest(findType(project, "TestSuite").getPackageFragment());
68+
JUnitExecutionTest.assertSuccessful(session);
69+
assertThat(session.getChildren()).isNotEmpty();
70+
}
71+
72+
@Test
73+
public void executeProject() throws Exception {
74+
ITestRunSession session = TestExecutionUtil.runTest(project);
75+
JUnitExecutionTest.assertSuccessful(session);
76+
assertThat(session.getChildren()).isNotEmpty();
77+
}
78+
79+
private static String toString(ITestRunSession session) {
80+
StringJoiner sb = new StringJoiner("\n");
81+
for (ITestElement element : session.getChildren()) {
82+
append(sb, element, 0);
83+
}
84+
return sb.toString();
85+
}
86+
87+
private static void append(StringJoiner sb, ITestElement element, int indent) {
88+
sb.add(" ".repeat(indent) + ((TestElement) element).getTestName());
89+
if (element instanceof ITestElementContainer container) {
90+
for (ITestElement child : container.getChildren()) {
91+
append(sb, child, indent + 1);
92+
}
93+
}
94+
}
95+
96+
}

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

Lines changed: 5 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
@@ -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") },

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, JUnit5SuiteExecutionTest.class, JUnit6SuiteExecutionTest.class })
2222
public class JUnitRuntimeTests {
2323

2424
}
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)