Skip to content

Commit 001deea

Browse files
committed
Migrate GenerateIdentifiersTest and LabelProviderTest to JUnit 5
Migrate performance tests to JUnit 5 to avoid dependency on PerformanceTestCaseJunit4. - Update UIPerformanceTestRule to implement BeforeAllCallback and AfterAllCallback. - Migrate GenerateIdentifiersTest and LabelProviderTest to use PerformanceMeter directly. - Use CloseTestWindowsExtension instead of CloseTestWindowsRule. - Add necessary JUnit 5 imports to MANIFEST.MF.
1 parent e81ba1c commit 001deea

File tree

4 files changed

+101
-76
lines changed

4 files changed

+101
-76
lines changed

tests/org.eclipse.ui.tests.performance/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.208.0",
2121
org.eclipse.ui.navigator.resources,
2222
org.eclipse.ui.genericeditor
2323
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
24+
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
25+
org.junit.jupiter.params;version="[5.14.0,6.0.0)",
26+
org.junit.jupiter.params.provider;version="[5.14.0,6.0.0)",
2427
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
2528
Bundle-ActivationPolicy: lazy
2629
Bundle-RequiredExecutionEnvironment: JavaSE-21

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/GenerateIdentifiersTest.java

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,53 @@
1717
import static org.eclipse.ui.PlatformUI.getWorkbench;
1818
import static org.eclipse.ui.tests.performance.UIPerformanceTestUtil.exercise;
1919

20-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
20+
import org.eclipse.test.performance.Performance;
21+
import org.eclipse.test.performance.PerformanceMeter;
2122
import org.eclipse.ui.activities.IActivityManager;
22-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
23-
import org.junit.ClassRule;
24-
import org.junit.Rule;
25-
import org.junit.Test;
23+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.TestInfo;
26+
import org.junit.jupiter.api.extension.RegisterExtension;
2627

2728
/**
2829
* @since 3.1
2930
*/
30-
public class GenerateIdentifiersTest extends PerformanceTestCaseJunit4 {
31+
public class GenerateIdentifiersTest {
3132

32-
@ClassRule
33-
public static final UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
33+
@RegisterExtension
34+
static UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
3435

35-
@Rule
36-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
36+
@RegisterExtension
37+
CloseTestWindowsExtension closeTestWindows = new CloseTestWindowsExtension();
3738

3839
private static final int count = 10000;
3940

4041
@Test
41-
public void test() throws Throwable {
42+
public void test(TestInfo testInfo) throws Throwable {
4243
final IActivityManager activityManager = getWorkbench().getActivitySupport().getActivityManager();
4344

44-
exercise(() -> {
45-
// construct the Identifiers to test
46-
final String[] ids = new String[count];
47-
for (int i = 0; i < ids.length; i++) {
48-
long timestamp = System.currentTimeMillis();
49-
ids[i] = "org.eclipse.jdt.ui/" + i + timestamp;
50-
}
51-
52-
startMeasuring();
53-
for (String id : ids) {
54-
activityManager.getIdentifier(id);
55-
}
56-
stopMeasuring();
57-
});
58-
commitMeasurements();
59-
assertPerformance();
45+
Performance perf = Performance.getDefault();
46+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
47+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
48+
try {
49+
exercise(() -> {
50+
// construct the Identifiers to test
51+
final String[] ids = new String[count];
52+
for (int i = 0; i < ids.length; i++) {
53+
long timestamp = System.currentTimeMillis();
54+
ids[i] = "org.eclipse.jdt.ui/" + i + timestamp;
55+
}
56+
57+
meter.start();
58+
for (String id : ids) {
59+
activityManager.getIdentifier(id);
60+
}
61+
meter.stop();
62+
});
63+
meter.commit();
64+
perf.assertPerformance(meter);
65+
} finally {
66+
meter.dispose();
67+
}
6068
}
6169
}

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/LabelProviderTest.java

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.processEvents;
1818
import static org.eclipse.ui.tests.performance.UIPerformanceTestUtil.exercise;
1919

20-
import java.util.Arrays;
21-
import java.util.Collection;
20+
import java.util.stream.Stream;
2221

2322
import org.eclipse.jface.tests.performance.JFacePerformanceSuite;
2423
import org.eclipse.jface.viewers.CellLabelProvider;
@@ -47,30 +46,29 @@
4746
import org.eclipse.swt.widgets.Display;
4847
import org.eclipse.swt.widgets.Shell;
4948
import org.eclipse.swt.widgets.Tree;
50-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
51-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
52-
import org.junit.After;
53-
import org.junit.Before;
54-
import org.junit.ClassRule;
55-
import org.junit.Rule;
56-
import org.junit.Test;
57-
import org.junit.runner.RunWith;
58-
import org.junit.runners.Parameterized;
59-
import org.junit.runners.Parameterized.Parameters;
49+
import org.eclipse.test.performance.Performance;
50+
import org.eclipse.test.performance.PerformanceMeter;
51+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
52+
import org.junit.jupiter.api.AfterEach;
53+
import org.junit.jupiter.api.BeforeEach;
54+
import org.junit.jupiter.api.TestInfo;
55+
import org.junit.jupiter.api.extension.RegisterExtension;
56+
import org.junit.jupiter.params.ParameterizedTest;
57+
import org.junit.jupiter.params.provider.Arguments;
58+
import org.junit.jupiter.params.provider.MethodSource;
6059

6160
/**
6261
* Test scrolling performance with various label styles
6362
*
6463
* @since 3.5
6564
*/
66-
@RunWith(Parameterized.class)
67-
public class LabelProviderTest extends PerformanceTestCaseJunit4 {
65+
public class LabelProviderTest {
6866

69-
@ClassRule
70-
public static final UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
67+
@RegisterExtension
68+
static UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule();
7169

72-
@Rule
73-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
70+
@RegisterExtension
71+
CloseTestWindowsExtension closeTestWindows = new CloseTestWindowsExtension();
7472

7573
private static class CountryEntry {
7674
private final String name;
@@ -173,25 +171,14 @@ public Font getFont(Object element) {
173171
private Shell fShell;
174172
private StructuredViewer fViewer;
175173

176-
private final boolean styled;
177-
private final boolean colors;
178-
179-
@Parameters
180-
public static Collection<Object[]> data() {
181-
return Arrays.asList(new Object[][] { { true, true }, { true, false }, { false, true }, { false, false } });
182-
}
183-
184-
/**
185-
* @param styled <code>true</code> to use DecoratingStyledCellLabelProvider
186-
* @param colors Run test with color on or off
187-
*/
188-
public LabelProviderTest(boolean styled, boolean colors) {
189-
this.styled = styled;
190-
this.colors = colors;
174+
public static Stream<Arguments> data() {
175+
return Stream.of(Arguments.of(true, true), Arguments.of(true, false), Arguments.of(false, true),
176+
Arguments.of(false, false));
191177
}
192178

193-
@Test
194-
public void test() throws Throwable {
179+
@ParameterizedTest
180+
@MethodSource("data")
181+
public void test(boolean styled, boolean colors, TestInfo testInfo) throws Throwable {
195182
if (styled)
196183
fViewer.setLabelProvider(getDecoratingStyledCellLabelProvider(colors));
197184
else
@@ -200,17 +187,25 @@ public void test() throws Throwable {
200187
final Tree tree = ((TreeViewer) fViewer).getTree();
201188
fShell.setFocus();
202189

203-
exercise(() -> {
204-
startMeasuring();
205-
for (int i = 0; i < ITEM_COUNT / 5; i++) {
206-
tree.setTopItem(tree.getItem(i * 5));
207-
processEvents();
208-
}
209-
stopMeasuring();
210-
}, MIN_ITERATIONS, ITERATIONS, JFacePerformanceSuite.MAX_TIME);
211-
212-
commitMeasurements();
213-
assertPerformance();
190+
Performance perf = Performance.getDefault();
191+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
192+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
193+
194+
try {
195+
exercise(() -> {
196+
meter.start();
197+
for (int i = 0; i < ITEM_COUNT / 5; i++) {
198+
tree.setTopItem(tree.getItem(i * 5));
199+
processEvents();
200+
}
201+
meter.stop();
202+
}, MIN_ITERATIONS, ITERATIONS, JFacePerformanceSuite.MAX_TIME);
203+
204+
meter.commit();
205+
perf.assertPerformance(meter);
206+
} finally {
207+
meter.dispose();
208+
}
214209
}
215210

216211
protected StructuredViewer createViewer(Shell parent) {
@@ -253,7 +248,7 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
253248
return viewer;
254249
}
255250

256-
@Before
251+
@BeforeEach
257252
public final void prepareShellUp() throws Exception {
258253
Display display = Display.getCurrent();
259254
if (display == null)
@@ -273,7 +268,7 @@ public final void prepareShellUp() throws Exception {
273268
fShell.open();
274269
}
275270

276-
@After
271+
@AfterEach
277272
public final void closeShell() throws Exception {
278273
if (fShell != null) {
279274
fShell.close();

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/UIPerformanceTestRule.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
import org.eclipse.ui.IWorkbenchPage;
2424
import org.eclipse.ui.IWorkbenchWindow;
2525
import org.eclipse.ui.PlatformUI;
26+
import org.junit.jupiter.api.extension.AfterAllCallback;
27+
import org.junit.jupiter.api.extension.BeforeAllCallback;
28+
import org.junit.jupiter.api.extension.ExtensionContext;
2629
import org.junit.rules.ExternalResource;
2730

28-
public class UIPerformanceTestRule extends ExternalResource {
31+
public class UIPerformanceTestRule extends ExternalResource implements BeforeAllCallback, AfterAllCallback {
2932
public static final String PERSPECTIVE1 = "org.eclipse.ui.tests.performancePerspective1";
3033
public static final String PERSPECTIVE2 = "org.eclipse.ui.tests.performancePerspective2";
3134

@@ -34,6 +37,22 @@ public class UIPerformanceTestRule extends ExternalResource {
3437
private static final String INTRO_VIEW = "org.eclipse.ui.internal.introview";
3538
public static final String[] EDITOR_FILE_EXTENSIONS = { "perf_basic", "perf_outline", "perf_text" };
3639

40+
@Override
41+
public void beforeAll(ExtensionContext context) throws Exception {
42+
try {
43+
before();
44+
} catch (Exception e) {
45+
throw e;
46+
} catch (Throwable e) {
47+
throw new RuntimeException(e);
48+
}
49+
}
50+
51+
@Override
52+
public void afterAll(ExtensionContext context) throws Exception {
53+
after();
54+
}
55+
3756
@Override
3857
protected void before() throws Throwable {
3958
IWorkbench workbench = PlatformUI.getWorkbench();

0 commit comments

Comments
 (0)