Run As -> JUnit test works in the base package (using scalatest 1.6.1 @RunWith[JUnitRunner] in a maven project, but not in other packages
This sounds like its a bug in walking the parent class hierarchy in base classes in other packages as it seems to work perfectly on all tests in a single package (which contains the class with the @RunWith[JUnitRunner] annotation, but not in any of the other tests in other packages (which all inherit the exact same class).
Steps to reproduce:
Close the archetypes and jrebel modules to get rid of the eclipse warnings (think its m2e stuff really).
Now try running the unit tests in the scalate-core project. They are all using scalatest 1.6.1 using the @RunWith[JUnitRunner] in the base class.
e.g. scalate-core/src/test/org/fusesource/scalate/TemplateEngineTest.scala, and select Run As -> I get 2 JUnit Test menu items; the first one with the key binding which works great - on all test classes in the org.fusesource.scalate package.
However if I try right clicking on any test case in a different package (which all inherit the same base test case class with the same annotation), I only get one JUnit Test entry in the Run As menu which doesn't work. i.e. I can run unit tests in the org.fusesource.scalate package fine, but any child package it doesn't work.
e.g. right clicking on scalate-core/src/test/org/fusesource/scalate/filter/CoffeeScriptFilterTest.scala (or expanding the file and right clicking on the only class inside that file) - you'll only see 1 JUnit Test entry which doesn't do anything; not the other entry with the keybinding on it which works if you select something in the org.fusesource.scalate package
Steps to reproduce:
git clone git://github.com/scalate/scalate.git
cd scalate
Close the archetypes and jrebel modules to get rid of the eclipse warnings (think its m2e stuff really).
Now try running the unit tests in the scalate-core project. They are all using scalatest 1.6.1 using the @RunWith[JUnitRunner] in the base class.
e.g. scalate-core/src/test/org/fusesource/scalate/TemplateEngineTest.scala, and select Run As -> I get 2 JUnit Test menu items; the first one with the key binding which works great - on all test classes in the org.fusesource.scalate package.
However if I try right clicking on any test case in a different package (which all inherit the same base test case class with the same annotation), I only get one JUnit Test entry in the Run As menu which doesn't work. i.e. I can run unit tests in the org.fusesource.scalate package fine, but any child package it doesn't work.
e.g. right clicking on scalate-core/src/test/org/fusesource/scalate/filter/CoffeeScriptFilterTest.scala (or expanding the file and right clicking on the only class inside that file) - you'll only see 1 JUnit Test entry which doesn't do anything; not the other entry with the keybinding on it which works if you select something in the org.fusesource.scalate package
Leave a comment
on 2011-11-08 16:14 *
By Matthew Farwell
How are you importing these projects into Eclipse? Are you doing "Import as existing Maven project" or just adding the directories manually. There don't seem to be any .project files in the repo, in fact they are ignored.
I could not build the project, missing `scalamd` dependency:
[WARNING] An error occurred during dependency resolution.
Failed to retrieve org.fusesource.scalamd:scalamd_2.9-1.6-SNAPSHOT
Caused by: Could not find artifact org.fusesource.scalamd:scalamd_2.9:jar:1.6-SNAPSHOT
Try downloading the file manually from the project website.
on 2012-12-13 12:56 *
By Mirco Dotta
Version changed from 2.0.0-beta12-29 to 2.0.2-final-29
Eclipse version changed from Indigo to Indigo - Eclipse 3.7
Assigned to changed from login to Mirco Dotta
Milestone set to Current
I'm very confident this will be fixed by https://github.com/scala-ide/scala-ide/pull/260
James, could you give it a try as soon as a nightly with the above PR merged is built.
James, could you give it a try as soon as a nightly with the above PR merged is built.
(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