Community
Participate
Working Groups
If I use a custom test runner such as Vert.x's VertxUnitRunner (https://vertx.io/docs/vertx-unit/java/#_junit_integration), Eclipse can't start single tests by selecting them. It can only start the whole file. That's because the matcher that selects the single test is broken. For example: @RunWith(VertxUnitRunner.class) public class JUnitTestSuite { @Test public void testSomething(TestContext context) { context.assertFalse(false); } } In https://github.com/eclipse/eclipse.jdt.ui/blob/master/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/JUnit4TestLoader.java#L34 I can see that testName will be "testSomething(TestContext)" instead of "testSomething(JUnitTestSuite)". Something is putting the parameter name in parenthesis instead of the test class name. Later, that testName is extracted in https://github.com/eclipse/eclipse.jdt.ui/blob/master/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/DescriptionMatcher.java#L134 to represent the test class name, and used to filter the test we're looking for. Which does not work because it will incorrectly look for a test belonging to the class "TestContext" and never find it. Apparently Eclipse uses "testName(parameterType)" where JUnit uses "testName(testClass)" and that only works for tests that don't take any parameter.
Which Eclipse version and which JUnit launcher did you use?
Oxygen.2 Release (4.7.2) with JUnit 4.12
Can you please try with Eclipse Oxygen 4.7 release build and Eclipse Photon 4.8 release build as well? This will help us in figuring out if the issue is due to any regression in 4.7.2 and if it is something that's already fixed in 4.8.
The issue is still present in Photon.
Build id: I20180801-2000 Reproduced against eclipse.jdt.ui master branch. It looks like when the test element selected is an IMethod, in org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationDelegate.java#collectExecutionArguments(..), the -test argument gets passed method.getDeclaringType().getFullyQualifiedName() + ':' + method.getElementName() . The 'method.getElementName()' is where 'testName(parameterType)' originates. The IMethod is created manually in evaluateTests(..) from the value of 'org.eclipse.jdt.junit.TESTNAME'. This seems to be set by the Junit Launch Tab, and is the displayed format of the method to be run. So simply taking out the the type parameter(s) (if they exist) in evaluateTests should resolve this. I can upload a rough change once I can confirm all tests pass.
New Gerrit change created: https://git.eclipse.org/r/126994
In the interest of understanding the issue better, I believe this regressed in Oxygen when type parameter data was introduced in various places (eg. JUnitLaunchConfigurationTab). It ultimately ended up stored in org.eclipse.jdt.junit.core.TESTNAME which was later used as a filter for which test to run. http://git.eclipse.org/c/gerrit/jdt/eclipse.jdt.ui.git/diff/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationTab.java?id=815287b20b0e86d27692b953e6e275b977f8c2b5
See comments on Gerrit.
Moving to 4.10. Not very safe to release the change at this point.
Found my way here as a result of tracing this exact issue through the JDT libraries when attempting to run a single JUnit 4 method using Jukito https://github.com/ArcBees/Jukito which allows for injection and multi-instance bindings of method parameters. I can confirm that the issue seems to begin with an incorrect pattern match for "className" in DescriptionMatcher when running a single method with parameters. We have been experiencing this since Oxygen (and now in Photon). Many of our automated test suites are built on JUnit 4 framework(s) that support test parameterization with a custom runner, and this has been a fairly big quality-of-life degradation. Workaround has been to first run the entire class, and then select the individual method from the JUnit UI and run it (but this requires initialization of the entire class first). Is there indeed no way to include this in 4.9 release? If not, what is the reasoning? I can't seem to find the release schedule for 4.10 yet, any info on when that is?
Gerrit change https://git.eclipse.org/r/126994 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=3207b1338106d8d6df839b3ddf5a264fd7e4bd15
(In reply to Eclipse Genie from comment #11) > Gerrit change https://git.eclipse.org/r/126994 was merged to [master]. > Commit: > http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=3207b1338106d8d6df839b3ddf5a264fd7e4bd15 Thanks, Roland. I have opened bug 541485 for the issue in navigating to the source.
Verified as fixed in I20181128-1800.