Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369818

Summary: Add OrderedTestSuite to org.eclipse.test.performance
Product: [Eclipse Project] Platform Reporter: Markus Keller <markus.kell.r>
Component: RelengAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, kim.moir, konigsberg, remy.suen
Version: 3.8   
Target Milestone: 4.2 M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
OrderedTestSuite.java
none
Patch none

Description Markus Keller CLA 2012-01-26 10:50:06 EST
Created attachment 210122 [details]
OrderedTestSuite.java

For performance tests, the execution order of test methods is often essential. 

In org.eclipse.jdt.ui.tests, we've implemented an OrderedTestSuite, which not only guarantees the execution order, but also emits an error if the test methods in a class don't correspond to the tests specified in the suite (e.g. if a new test got added, but is missing in the suite).

This replaces manual patterns like this:

public static Test suite() {
    // we must make sure that cold is executed before warm
    TestSuite suite= new TestSuite("RenamePackagePerfTests1");
    suite.addTest(new RenamePackagePerfTests1("testCold_10_10"));
    suite.addTest(new RenamePackagePerfTests1("test_10_10"));
    suite.addTest(new RenamePackagePerfTests1("test_100_10"));
    suite.addTest(new RenamePackagePerfTests1("test_1000_10"));
    return new RefactoringPerformanceTestSetup(suite);
}

... with safer and less verbose code like this:

public static Test suite() {
    // we must make sure that cold is executed before warm
    return new OrderedTestSuite(RenamePackagePerfTests1.class, new String[] {
        "testCold_10_10", "test_10_10", "test_100_10", "test_1000_10"
    });
}
Comment 1 Markus Keller CLA 2012-01-26 14:16:20 EST
Created attachment 210148 [details]
Patch

Sorry, I forgot that the org.eclipse.test.performance project didn't use API Tools. Here's a complete patch that fixes the project setup and adds the OrderedTestSuite.

I also added a little tweak to the generated test errors if a test is missing or not listed: Opening the error from the JUnit view works now.
Comment 2 Dani Megert CLA 2012-01-27 09:07:43 EST
Fixed in master: 83eac8e066f499629737a7c7e93dc765db3640eb
Comment 3 Markus Keller CLA 2012-01-27 12:03:31 EST
This can also be useful for other tests that suffer from this JDK 7 bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7023180
They decided to leave Class#getDeclaredMethods() unpredictable, although the declaration order is the only reasonable order.

The patch in bug 337707 contains a sketch of an OrderedRunner class that could be used to achieve the same in JUnit 4 (needs documentation and more code to detect and report missing tests).
Comment 4 Dani Megert CLA 2012-02-03 02:16:33 EST
Just a reminder for those using the OrderedTestSuite: don't forget to replace
addTest(new TestSuite(YourTests.class));
with
addTest(YourTests.suite());
Comment 5 Dani Megert CLA 2012-08-02 02:28:19 EDT
*** Bug 386453 has been marked as a duplicate of this bug. ***