Implement JUnitTestFinder in Scala
One of the longest standing problem in the IDE is unreliable test finding. The reason is the Java implementation, that relies on it's own `HierarchyResolver`, that many times tries to parse (using the Java parser, evidently) compilation units.
We could implement the JUnitTestRunner ourselves and break from from the Java implementation. All in all, it amounts to implementing
where `element` can be anything (project, package, source file, etc).
We could implement the JUnitTestRunner ourselves and break from from the Java implementation. All in all, it amounts to implementing
def findTestsInContainer(element: IJavaElement, pm: IProgressMonitor)
where `element` can be anything (project, package, source file, etc).
Leave a comment
on 2012-12-07 15:07 *
By Mirco Dotta
I believe this ticket is related to #1000782
on 2012-12-13 15:52 *
By Mirco Dotta
(In scala-ide:1891f62e2ce92f15591b4e9a5472b392a6c8f1d7) Show Run As > JUnit Test when right clicking on a source that contains runnable
JUnit Test classes
If a source is closed (i.e., it hasn't been typechecked yet - this is
important!) and, through the package explorer, you right click and select Run
As, no "JUnit Test" option used to be shown.
The problem was that if the source is not opened (and typechecked), the
``@Test`` annotation can only be found in the AST, and not in the symbol. The
fix is to always initialize the member's symbol before looking if it declares
the ``@Test`` annotation. By doing so, the ``@Test`` annotation is found also
for members inherited from a superclass or a trait!
In this commit I've also implemented the missing logic for considering the
JUnit4 ``@RunWith`` annotation. Basically, if a class or any of its inherited
types specify the ``@RunWith`` annotation, then the class is a valid,
runnable, JUnit4 test class.
As part of this commit I've also made some improvements to the existing testing
class (formerly named ``LaunchableTesters``, now splitted into two distinct
classes: ``MainMethodFinderTest`` and ``RunAsTest``).
The work on these tickets (Re #1001379, Re #1001380) was somewhat motivated by
(or a consequence of) Re #1001304 and Re #1001275.
Finally, I'm quite convinced that the ``ScalaLaunchShortcut.getMainMethods``
could use some similar love, but this should be done in a separate PR(there is
already enough meat here).
Fix #1001234, Fix #1001379, Fix #1001380 and Fix #1000731.
Branch: master
JUnit Test classes
If a source is closed (i.e., it hasn't been typechecked yet - this is
important!) and, through the package explorer, you right click and select Run
As, no "JUnit Test" option used to be shown.
The problem was that if the source is not opened (and typechecked), the
``@Test`` annotation can only be found in the AST, and not in the symbol. The
fix is to always initialize the member's symbol before looking if it declares
the ``@Test`` annotation. By doing so, the ``@Test`` annotation is found also
for members inherited from a superclass or a trait!
In this commit I've also implemented the missing logic for considering the
JUnit4 ``@RunWith`` annotation. Basically, if a class or any of its inherited
types specify the ``@RunWith`` annotation, then the class is a valid,
runnable, JUnit4 test class.
As part of this commit I've also made some improvements to the existing testing
class (formerly named ``LaunchableTesters``, now splitted into two distinct
classes: ``MainMethodFinderTest`` and ``RunAsTest``).
The work on these tickets (Re #1001379, Re #1001380) was somewhat motivated by
(or a consequence of) Re #1001304 and Re #1001275.
Finally, I'm quite convinced that the ``ScalaLaunchShortcut.getMainMethods``
could use some similar love, but this should be done in a separate PR(there is
already enough meat here).
Fix #1001234, Fix #1001379, Fix #1001380 and Fix #1000731.
Branch: master
(In scala-ide:d9157e8e9d6864bf0ba07a3faf3e13ac3307eaca) Implemented JUnit test finder logic in Scala.
Works for both Scala and Java sources, and adds a 'Scala JUnit' test kind and shortcut for 'Run As'.
We hook this test finder using an internal extension point defined by `org.eclipse.jdt.junit.core`, `internal_testkinds`. This class is used both when right-clicking on a Java element and choosing "Run As - Scala JUnit test" and when hitting the "Search" button in the JUnit Run configuration dialog.
Alternatives were considered, but not pursued:
Fixed #1001275, Fixed #1000782.
Branch: master
Works for both Scala and Java sources, and adds a 'Scala JUnit' test kind and shortcut for 'Run As'.
We hook this test finder using an internal extension point defined by `org.eclipse.jdt.junit.core`, `internal_testkinds`. This class is used both when right-clicking on a Java element and choosing "Run As - Scala JUnit test" and when hitting the "Search" button in the JUnit Run configuration dialog.
Alternatives were considered, but not pursued:
- AspectJ to hook into the JUnit runner. Discarded as hackish, not future-proof and the risk of breaking the plain JDT plugin
- implement a Scala JUnit configuration type, but that would duplicate more of the JUnit configuration type and involved rewriting dialogs and buttons
Fixed #1001275, Fixed #1000782.
Branch: master