Run as JUnit Test does not detect test superclass having @RunWith(classOf[JUnitRunner])
Hi,
When a specs2 spec extends SpecificationWithJUnit, which has @RunWith(classOf[JUnitRunner]), the menu option for running the test is not available. However, if you add the @RunWith(classOf[JUnitRunner]) annotation the menu item becomes available.
When a specs2 spec extends SpecificationWithJUnit, which has @RunWith(classOf[JUnitRunner]), the menu option for running the test is not available. However, if you add the @RunWith(classOf[JUnitRunner]) annotation the menu item becomes available.
Leave a comment
on 2012-10-11 05:43 *
By Iulian Dragos
Can you please provide a complete example we use to reproduce this?
on 2012-10-11 14:11 *
By Channing Walton
When trying to produce a standalone project I discovered more - I'll put the project on github soon though.
If the import for SpecificationWithJUnit is import org.specs2.mutable.SpecificationWithJUnit then it works, you see the Run JUnit Test menu item and the test will run ok.
If the import is import org.specs2.mutable._ then the menu is not there.
If the import for SpecificationWithJUnit is import org.specs2.mutable.SpecificationWithJUnit then it works, you see the Run JUnit Test menu item and the test will run ok.
If the import is import org.specs2.mutable._ then the menu is not there.
on 2012-10-15 03:44 *
By Iulian Dragos
Milestone changed from To Discuss to Backlog
Priority changed from Normal (3) to Low (4)
(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
on 2012-12-13 13:44 *
By Channing Walton
Thanks Mirco
on 2012-12-13 16:26 *
By Mirco Dotta
Thank you for reporting this. We'll have a V2.1 Milestone 3 soon, and this fix will be included, please report back if you see any glitch.