Community
Participate
Working Groups
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...".
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.
> 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; } }
There is a fix in 4.6. Expect a release candidate before April 15.