JUnit test discovery is not working on Indigo
In Eclipse 3.7.x, trying to launch all JUnit tests of a project or package is mostly not working. If a test is open in an editor, it might get picked up.
The only solution to run tests is to select a test class or a test suite class.
On a new workspace:
Tested on Eclipse-3.7/ScalaIDE-29-rc2, Eclipse-3.7.1/ScalaIDE-29-rc1 and Eclipse-3.7.1/ScalaIDE-29-rc2.
Works fine on Eclipse-3.6.2/ScalaIDE-29-rc2
The only solution to run tests is to select a test class or a test suite class.
On a new workspace:
- Create a Scala project
- Add the JUnit 4 library to the build path.
- Create a Scala class with a JUnit 4 test in it.
- Do 'Run As > JUnit Test' on the project
- Close all editors
- Shutdown Scala IDE
- Restart Scala IDE
- Do 'Run As > JUnit Test' on the project
Tested on Eclipse-3.7/ScalaIDE-29-rc2, Eclipse-3.7.1/ScalaIDE-29-rc1 and Eclipse-3.7.1/ScalaIDE-29-rc2.
Works fine on Eclipse-3.6.2/ScalaIDE-29-rc2
Leave a comment
Additional info:
-----
When eclipse starts hunting for tests it spits this to its stdout:
Those messages are logged at line 22 of scala.tools.eclipse.javaelements.ScalaMatchLocator.scala (side note: those patterns come from org.eclipse.jdt.internal.junit.launcher.JUnit4TestFinder). The duplication in the log is just an artifact of the way the "OR" pattern is implemented.
-----
I am using specs2, and the search consistently fails when I extend SpecificationWithJUnit, yet consistently works when I extend Specification and directly annotate my class with @RunWith. This suggests that the problem lies in the TypeReferenceLocator class (defined at line 245 of the previously mentioned ScalaMatchLocator.scala)...
When TypeReferenceLocator checks for the presence of an annotation it must inspect that annotation to see if it has the @Inherited meta-annotation (as @RunWith does), and if so then it must check all superclasses (see section 9.6.1.3 of Java Lang Spec). I can't find any code that implements this behavior.
Note that @RunWith is a Java annotation. The rules for Scala annotations are a bit of a mystery to me still. The Lang Spec doesn't mention inheritance of annotations at all.
-----
Jeremy
-----
When eclipse starts hunting for tests it spits this to its stdout:
[ScalaPresentationCompiler] Search pattern TypeReferencePattern: qualification<org.junit.runner>, type<RunWith>, exact match, case sensitive, generic full match, fine grain: ANNOTATION_TYPE_REFERENCE
| TypeReferencePattern: qualification<org.junit>, type<Test>, exact match, case sensitive, generic full match, fine grain: ANNOTATION_TYPE_REFERENCE
[ScalaPresentationCompiler] Search pattern TypeReferencePattern: qualification<org.junit.runner>, type<RunWith>, exact match, case sensitive, generic full match, fine grain: ANNOTATION_TYPE_REFERENCE
[ScalaPresentationCompiler] Search pattern TypeReferencePattern: qualification<org.junit>, type<Test>, exact match, case sensitive, generic full match, fine grain: ANNOTATION_TYPE_REFERENCE
Those messages are logged at line 22 of scala.tools.eclipse.javaelements.ScalaMatchLocator.scala (side note: those patterns come from org.eclipse.jdt.internal.junit.launcher.JUnit4TestFinder). The duplication in the log is just an artifact of the way the "OR" pattern is implemented.
-----
I am using specs2, and the search consistently fails when I extend SpecificationWithJUnit, yet consistently works when I extend Specification and directly annotate my class with @RunWith. This suggests that the problem lies in the TypeReferenceLocator class (defined at line 245 of the previously mentioned ScalaMatchLocator.scala)...
When TypeReferenceLocator checks for the presence of an annotation it must inspect that annotation to see if it has the @Inherited meta-annotation (as @RunWith does), and if so then it must check all superclasses (see section 9.6.1.3 of Java Lang Spec). I can't find any code that implements this behavior.
Note that @RunWith is a Java annotation. The rules for Scala annotations are a bit of a mystery to me still. The Lang Spec doesn't mention inheritance of annotations at all.
-----
Jeremy
I believe Iulian's upcoming fix, together with the fixes for #1001379 and #1001380 will make this work as expected. I'm assigning this to Iulian and set its status to Test, but I'm confident this it can be closed as soon as #1001275 is fixed. Iulian, I hope you don't mind I have assigned this to you.
on 2012-12-13 15:26 *
By Mirco Dotta
Type set to Defect
Version changed from 2.0.0-RC2-29 to 2.0.2-final-29
Eclipse version changed from Indigo to Indigo - Eclipse 3.7
Milestone changed from Helium to Current
(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