Skip to content

Commit 3d42a70

Browse files
committed
Migrate JFace Performance Tests to JUnit 5
Migrate the following tests to JUnit 5: - ViewerTest - ProgressMonitorDialogPerformanceTest - ListPopulationTest - FileImageDescriptorTest - SWTTreeTest - CollatorPerformanceTest Changes include: - Removing inheritance from PerformanceTestCaseJunit4 - Using CloseTestWindowsExtension - Using PerformanceMeter directly - Using TestInfo for scenario ID - Updating imports - Adding necessary packages to MANIFEST.MF
1 parent 66bef1b commit 3d42a70

6 files changed

Lines changed: 274 additions & 156 deletions

File tree

tests/org.eclipse.ui.tests.performance/src/org/eclipse/jface/tests/performance/CollatorPerformanceTest.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
import java.util.Comparator;
2020

2121
import org.eclipse.jface.util.Policy;
22-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
22+
import org.eclipse.test.performance.Performance;
23+
import org.eclipse.test.performance.PerformanceMeter;
2324
import org.eclipse.ui.tests.performance.UIPerformanceTestRule;
24-
import org.junit.ClassRule;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.TestInfo;
27+
import org.junit.jupiter.api.extension.RegisterExtension;
2628

2729
/**
2830
* @since 3.5
2931
*/
30-
public class CollatorPerformanceTest extends PerformanceTestCaseJunit4 {
32+
public class CollatorPerformanceTest {
3133

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

3537
private static final int ARRAYSIZE=100000;
3638
private static String[] fArray;
@@ -43,16 +45,24 @@ public CollatorPerformanceTest() {
4345
* test Collator by sorting the array
4446
*/
4547
@Test
46-
public void testCollator(){
48+
public void testCollator(TestInfo testInfo) {
49+
Performance perf = Performance.getDefault();
50+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
51+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
52+
4753
Comparator<Object> comparator=Policy.getComparator();
48-
for (int i = 0; i < 15; i++) {
49-
String[] array=fArray.clone();
50-
startMeasuring();
51-
Arrays.sort(array, comparator);
52-
stopMeasuring();
54+
try {
55+
for (int i = 0; i < 15; i++) {
56+
String[] array=fArray.clone();
57+
meter.start();
58+
Arrays.sort(array, comparator);
59+
meter.stop();
60+
}
61+
meter.commit();
62+
perf.assertPerformance(meter);
63+
} finally {
64+
meter.dispose();
5365
}
54-
commitMeasurements();
55-
assertPerformance();
5666
}
5767

5868
/**

tests/org.eclipse.ui.tests.performance/src/org/eclipse/jface/tests/performance/FileImageDescriptorTest.java

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,71 +26,81 @@
2626
import org.eclipse.core.runtime.IPath;
2727
import org.eclipse.jface.resource.ImageDescriptor;
2828
import org.eclipse.swt.graphics.Image;
29-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
30-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
31-
import org.junit.Rule;
32-
import org.junit.Test;
29+
import org.eclipse.test.performance.Performance;
30+
import org.eclipse.test.performance.PerformanceMeter;
31+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.TestInfo;
34+
import org.junit.jupiter.api.extension.RegisterExtension;
3335
import org.osgi.framework.Bundle;
3436
import org.osgi.framework.FrameworkUtil;
3537

3638
/**
3739
* ComboViewerRefreshTest is a test of refreshes of difference size in the combo
3840
* viewer.
3941
*/
40-
public class FileImageDescriptorTest extends PerformanceTestCaseJunit4 {
42+
public class FileImageDescriptorTest {
4143

42-
@Rule
43-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
44+
@RegisterExtension
45+
CloseTestWindowsExtension closeTestWindows = new CloseTestWindowsExtension();
4446

4547
protected static final String IMAGES_DIRECTORY = "/icons/imagetests";
4648

4749
/**
4850
* Test the time for doing a refresh.
4951
*/
5052
@Test
51-
public void testRefresh() throws Throwable {
53+
public void testRefresh(TestInfo testInfo) throws Throwable {
5254

53-
exercise(() -> {
54-
Class<?> missing = null;
55-
ArrayList<Image> images = new ArrayList<>();
55+
Performance perf = Performance.getDefault();
56+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
57+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
5658

57-
Bundle bundle = FrameworkUtil.getBundle(getClass());
58-
Enumeration<String> bundleEntries = bundle.getEntryPaths(IMAGES_DIRECTORY);
59+
try {
60+
exercise(() -> {
61+
Class<?> missing = null;
62+
ArrayList<Image> images = new ArrayList<>();
5963

64+
Bundle bundle = FrameworkUtil.getBundle(getClass());
65+
Enumeration<String> bundleEntries = bundle.getEntryPaths(IMAGES_DIRECTORY);
6066

61-
while (bundleEntries.hasMoreElements()) {
62-
ImageDescriptor descriptor;
63-
String localImagePath = bundleEntries.nextElement();
6467

65-
if (localImagePath.indexOf('.') < 0)
66-
continue;
68+
while (bundleEntries.hasMoreElements()) {
69+
ImageDescriptor descriptor;
70+
String localImagePath = bundleEntries.nextElement();
6771

68-
URL[] files = FileLocator.findEntries(bundle, IPath.fromOSString(localImagePath));
72+
if (localImagePath.indexOf('.') < 0)
73+
continue;
6974

70-
for (URL file : files) {
71-
startMeasuring();
72-
descriptor = ImageDescriptor.createFromFile(missing, FileLocator.toFileURL(file).getFile());
75+
URL[] files = FileLocator.findEntries(bundle, IPath.fromOSString(localImagePath));
7376

74-
for (int j = 0; j < 10; j++) {
75-
Image image = descriptor.createImage();
76-
images.add(image);
77-
}
77+
for (URL file : files) {
78+
meter.start();
79+
descriptor = ImageDescriptor.createFromFile(missing, FileLocator.toFileURL(file).getFile());
7880

79-
processEvents();
80-
stopMeasuring();
81+
for (int j = 0; j < 10; j++) {
82+
Image image = descriptor.createImage();
83+
images.add(image);
84+
}
8185

82-
}
86+
processEvents();
87+
meter.stop();
88+
89+
}
8390

84-
}
91+
}
8592

8693

87-
Iterator<Image> imageIterator = images.iterator();
88-
while (imageIterator.hasNext()) {
89-
imageIterator.next().dispose();
90-
}
91-
}, 20, 100, JFacePerformanceSuite.MAX_TIME);
94+
Iterator<Image> imageIterator = images.iterator();
95+
while (imageIterator.hasNext()) {
96+
imageIterator.next().dispose();
97+
}
98+
}, 20, 100, JFacePerformanceSuite.MAX_TIME);
9299

93-
commitMeasurements();
94-
assertPerformance();
100+
meter.commit();
101+
perf.assertPerformance(meter);
102+
} finally {
103+
meter.dispose();
104+
}
95105
}
96106
}

tests/org.eclipse.ui.tests.performance/src/org/eclipse/jface/tests/performance/ListPopulationTest.java

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@
2222
import org.eclipse.swt.widgets.Display;
2323
import org.eclipse.swt.widgets.List;
2424
import org.eclipse.swt.widgets.Shell;
25-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
26-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
27-
import org.junit.Rule;
28-
import org.junit.Test;
25+
import org.eclipse.test.performance.Performance;
26+
import org.eclipse.test.performance.PerformanceMeter;
27+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.TestInfo;
30+
import org.junit.jupiter.api.extension.RegisterExtension;
2931

3032
/**
3133
* The ListPopulationTest is the test for simple
3234
* SWT lists.
3335
*/
34-
public class ListPopulationTest extends PerformanceTestCaseJunit4 {
36+
public class ListPopulationTest {
3537

36-
@Rule
37-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
38+
@RegisterExtension
39+
CloseTestWindowsExtension closeTestWindows = new CloseTestWindowsExtension();
3840

3941
List list;
4042

@@ -52,72 +54,89 @@ protected void openBrowser() {
5254
}
5355

5456
@Test
55-
public void testSmallAdd() throws Throwable {
56-
addBench(100);
57+
public void testSmallAdd(TestInfo testInfo) throws Throwable {
58+
addBench(100, testInfo);
5759
}
5860

5961
@Test
60-
public void testSmallSetItems() throws Throwable {
61-
setItemsBench(100);
62+
public void testSmallSetItems(TestInfo testInfo) throws Throwable {
63+
setItemsBench(100, testInfo);
6264
}
6365

6466
@Test
65-
public void testMediumAdd() throws Throwable {
66-
addBench(5000);
67+
public void testMediumAdd(TestInfo testInfo) throws Throwable {
68+
addBench(5000, testInfo);
6769
}
6870

6971
@Test
70-
public void testMediumSetItems() throws Throwable {
71-
setItemsBench(5000);
72+
public void testMediumSetItems(TestInfo testInfo) throws Throwable {
73+
setItemsBench(5000, testInfo);
7274
}
7375

7476
@Test
75-
public void testLargeAdd() throws Throwable {
76-
addBench(50000);
77+
public void testLargeAdd(TestInfo testInfo) throws Throwable {
78+
addBench(50000, testInfo);
7779
}
7880

7981
@Test
80-
public void testLargeSetItems() throws Throwable {
81-
setItemsBench(50000);
82+
public void testLargeSetItems(TestInfo testInfo) throws Throwable {
83+
setItemsBench(50000, testInfo);
8284
}
8385

8486
/**
8587
* Test the time for adding elements using add.
8688
*/
87-
public void addBench(int count) throws Throwable {
89+
public void addBench(int count, TestInfo testInfo) throws Throwable {
8890
openBrowser();
8991
final String [] items = getItems(count);
9092

91-
exercise(() -> {
92-
list.removeAll();
93-
startMeasuring();
94-
for (String item : items) {
95-
list.add(item);
96-
}
97-
processEvents();
98-
stopMeasuring();
99-
});
100-
101-
commitMeasurements();
102-
assertPerformance();
93+
Performance perf = Performance.getDefault();
94+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
95+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
96+
97+
try {
98+
exercise(() -> {
99+
list.removeAll();
100+
meter.start();
101+
for (String item : items) {
102+
list.add(item);
103+
}
104+
processEvents();
105+
meter.stop();
106+
});
107+
108+
meter.commit();
109+
perf.assertPerformance(meter);
110+
} finally {
111+
meter.dispose();
112+
}
103113
}
104114

105115
/**
106116
* Test the time for adding elements using setItem.
107117
*/
108-
public void setItemsBench(int count) throws Throwable {
118+
public void setItemsBench(int count, TestInfo testInfo) throws Throwable {
109119
openBrowser();
110120
final String [] items = getItems(count);
111-
exercise(() -> {
112-
list.removeAll();
113-
startMeasuring();
114-
list.setItems(items);
115-
processEvents();
116-
stopMeasuring();
117-
});
118-
119-
commitMeasurements();
120-
assertPerformance();
121+
122+
Performance perf = Performance.getDefault();
123+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
124+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
125+
126+
try {
127+
exercise(() -> {
128+
list.removeAll();
129+
meter.start();
130+
list.setItems(items);
131+
processEvents();
132+
meter.stop();
133+
});
134+
135+
meter.commit();
136+
perf.assertPerformance(meter);
137+
} finally {
138+
meter.dispose();
139+
}
121140
}
122141

123142
/**

0 commit comments

Comments
 (0)