Bug 270788 - [JUnit] "Run As > JUnit Test" on inherited test method
Summary: [JUnit] "Run As > JUnit Test" on inherited test method
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4.2   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-01 10:10 EDT by J. Lewis Muir CLA
Modified: 2009-04-02 09:29 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description J. Lewis Muir CLA 2009-04-01 10:10:56 EDT
I would like to request support for a right-click "Run As > JUnit Test" in the Hierarchy view of the Java Browsing perspective on a test method inherited from a superclass.

(Or, I'd also be OK with a right-click menu item on a test class, perhaps "Run As > Junit Test...", that would display all test methods (including inherited ones) and let me select which test methods to run.  This is like enhancement 40598.)

Here's my situation.  I have a test class, AdscTest, that is a subclass of an abstract test class, DriverTest.  Both contain test case methods marked with the @Test annotation.

I can right-click on AdscTest in the Types view of the Java Browsing perspective and choose "Run As > JUnit Test" and all the test methods with the @Test annotation, including those in DriverTest, will be run.  I can also right-click on any AdscTest test method in the Members view and choose "Run As > JUnit Test" and just that method will be run.

However, I have no way to run a test method that AdscTest inherits.  I tried opening AdscTest in the Hierarchy view and selecting "Show All Inherited Members".  I right-clicked on an inherited test method, but the "Run As" menu only contained "Run Configurations...".
Comment 1 Markus Keller CLA 2009-04-01 15:25:08 EDT
The inherited methods shown in the type hierarchy view are still the methods in their declaring type. We should not add special meaning to these elements just because they show up in the type hierarchy under a subtype.

Would something like bug 83651 help (i.e. make the "Test method" in the Run Configurations dialog editable)?

You could also try to write your own org.junit.runner.Runner that just runs a single method.
Comment 2 Markus Keller CLA 2009-04-02 03:38:34 EDT
> You could also try to write your own org.junit.runner.Runner that just runs a
> single method.

Maybe David knows an easier way to write a JUnit 4 test class that runs just one test method of a given test. In JUnit 3, this was as easy as this:

public class RunOne {
	public static Test suite() {
		TestCase test= new SimpleTest();
		test.setName("testAdd");
		
		TestSuite suite= new TestSuite();
		suite.addTest(test);
		return suite;
	}
}
Comment 3 David Saff CLA 2009-04-02 09:29:03 EDT
There is a fix in 4.6.  Expect a release candidate before April 15.