Community
Participate
Working Groups
It would be awesome if the JDT JUnit View could re-run suites that are not explicitly backed by a Testclass, Suiteclass, or Method. Such 'virtual' suites are common if you use custom runners, such as org.junit.runners.Parameterized. Here, the each 'virtual' suite describes as set of parameters for which each test method is executed. A bug for it has been filed here: bug 434093. I'm filing this bug because I'd like to propose a solution that works with all custom runners and not just junit.Parameterized. Every JUnit runner first creates a tree of org.junit.runner.Description-Objects. Each Description represents a test or suite... currently, JDT can only re-run Descriptions that represent a Java Test- or Suite-Class or a test Method. I'd like to propose that, for other cases, i.e. when the Description is not backed by a class/method, the parent Description should be the root for test execution and all unwanted siblings of the to-be-executed test can be filtered out with org.junit.runner.manipulation.Filter. My personal use case is http://www.xpect-tests.org. There, 'virtual' tests represent a file or a Java method plus parameters. I've hacked a working solution and made it available in https://github.com/meysholdt/eclipse_jdt_junit_runners/tree/master/org.eclipse.jdt.junit4.runtime.patch I'd be happy to clean it up and make a contribution.
I've pushed contributions to https://git.eclipse.org/r/33188 improved tests coverage for junit4 test execution https://git.eclipse.org/r/33189 run subtrees of junit tests or a Java method when using custom runners From the commit message: ------------------------ For example, for the following tree of tests that you might get from JUnit’s ‘Parameterized’ runner —————————————- MyTestClass [0] testMethod[0] testMethod2[0] [1] testMethod[1] testMethod2[1] —————————————- it is now possible to run only —————————————- [1] testMethod[1] testMethod2[1] —————————————- by clicking on the “run” action on “[1]” in the JUnit View. Furthermore, it is possible to execute —————————————- MyTestClass [0] testMethod2[0] [1] testMethod2[1] —————————————- by choosing “run as” -> “JUnit Test” on the Java Method “testMethod2”. To make this possible, this contribution contains the following changes: - if a test suite (e.g. “[1]”) has no class, the containers test class is executed and the suite’s name is passed to the runner as the testName. The test runner will then filter JUnit’s tree of test descriptions accordingly. - The runner now combines three strategies to filter test descriptions: - If the test name is specified as “foo (bar)” (this is JUnit’s formant), the test description that is an exact match will be executed. - If the test name is “foo”, the runner will execute suites with the name “foo” and methods that have the name “foo” and are in the root tests’s class. - in addition to the two cases above, and if foo is a valid Java identifier, all test cases will be matched if the leading part of their description’s name that is also a Java identifier, equals foo. These changes are not specific to the 'Parameterized' runner and are intend to work with all custom runners. For the method-based filitering, however, a runner needs to prefix test descriptions the method name. ------------------------ I hope you consider this contribution to be useful. I tried to keep the quality of the contribution high, but this is still a fist shot, and it would be wonderful to have some feedback on it.
I'm not sure if somebody found the time to look at this contribution, but it would be really great to have some feedback and discussion on how we can continue from here.
Markus, please have a look.
> https://git.eclipse.org/r/33188 improved tests coverage for junit4 test > execution Thanks, pushed as http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=de90ad8e2f8a6ced3368a0b475654e03bbc6f4fe > https://git.eclipse.org/r/33189 run subtrees of junit tests or a Java method > when using custom runners Will review tomorrow.
Sorry, didn't find a big enough time slot to review https://git.eclipse.org/r/33189 .
*** Bug 434093 has been marked as a duplicate of this bug. ***
What is the status of this patch? I would very much like to have this functionality in 4.5 if possible.
The patch is feature-complete and has test coverage. I'm waiting for the JDT team to suggest improvements or merge it.
Thanks, looks good. Sorry for the long delay. Pushed as http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=3b64020e89d0cefe9dca260edf6f9f633a03f4e9 and adjusted a few things with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=94f85f49f97873b37d3444cf7f2c003d71348970 : - removed @SuppressWarnings("unused") on exception parameters, since these problems will be put into a separate compiler option and disabled for Mars. - added missing copyright headers to new files - fixed API Tools errors - removed exception thrown in JUnitLaunchShortcut#createLaunchConfiguration(IJavaElement, String). The exception was not documented in the API, and I don't see much harm in just considering the testName as discardable input in that special case.
Awesome, thank you! I'm fine with your adjustments.
I blogged about this here: http://blog.moritz.eysholdt.de/2014/11/new-eclipse-junit-feature-run-subtrees.html
(In reply to Moritz Eysholdt from comment #11) > I blogged about this here: > http://blog.moritz.eysholdt.de/2014/11/new-eclipse-junit-feature-run-subtrees.html > Nice!
Moritz, this was contributed before the great fixes period/competition started.
that's a pitty ;)
For parametrized test cases, this feature is restricted to "constant" test names which are precisely reproducible between two executions. The default @Parameters annotation ensures this by using only the index as a name. However, problems arise when specifying custom test names as for example: @Parameters(name = "{0}") This will invoke toString() on the parameter at position 0, whereas the default implementation of toString() doesn't give constant values. I wonder if it is possible to use some "constant" identifier to filter the tree, for example using only the index instead of the user-defined test name.
This bug occurs when character '\n' is being used in the title. e.g. @Parameters( name = "{0}" ) public static List<Object[]> testCases(){ return Arrays.asList( new Object[]{ "This is a working title" }, new Object[]{ "This is a buggy title\nThis is a title" } ); }
(In reply to Isaac Gainey from comment #16) > This bug occurs when character '\n' is being used in the title. > > e.g. > > @Parameters( name = "{0}" ) > public static List<Object[]> testCases(){ > return Arrays.asList( new Object[]{ "This is a working title" }, > new Object[]{ "This is a buggy title\nThis is a > title" } ); > } This bug is closed. If you see a problem using Photon M7 (4.8 M7), then please file a new bug report.