I'm taking the Martin Odersky Coursera class and the assignments use ScalaTest. It's quite annoying that Eclipse can't locate the test methods on double click or right-click "Go to File" in the JUnit runner.
Upon double click, a "Method 'xxx' not found. Opening the test class." dialog pops up.
Is there a configuration problem or is this a ScalaTest bug/limitation?
Here's a sample ScalaTest from the class:
package recfun
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class CountChangeSuite extends FunSuite {
import Main.countChange
test("manual") {
assert(countChange(4,List(1,2)) === 3)
}
}
You can use the ScalaTest Eclipse plugin with ScalaTest 1.8. But when you run your tests it will pop up a GUI. Useful, but not as nice as the ScalaTest 2.0 integration. I think with the Coursera course you are using 1.8.
The actual problem you're having with JUnit is one that we have tried to solve in ScalaTest. JUnit is not only a test framework, it is also a testing platform that you can run other frameworks through via its @RunWith annotation. In this case you're running ScalaTest through JUnit. But you don't get full IDE support with a @RunWith annotation, you just get the ability to run. This is indeed a limitation of JUnit. What you would like is to get IDE support too for that test framework you're running through JUnit (in this case ScalaTest). The only way to do that with JUnit is to write IDE plugins for your test framework, which is a lot of work.
We have been working on that as part of the ScalaTest project, making plugins or helping make plugins that give ScalaTest users full IDE support. But as part of that effort we also came up with the concept of a "Finder" that can be used to give other test frameworks full IDE support when they are run through ScalaTest. (I.e., just as you can run other test frameworks through JUnit, you can also run other test frameworks through ScalaTest.) You can see some examples of Finders giving IDE support at the end of this video (about 10 minutes into the video):
http://skillsmatter.com/podcast/scala/scalatest-scalamock-subcut
Yes, it's a known bug in the JUnit plugin for Eclipse. It's also very hard to solve (for the jun it plugin).
Basically, The Eclipse junit plugin expects there to be a method, which there will be for all java JUnit tests, but this isn't necessarily the case for ScalaTest tests, especially Suites & Specs.
However, you can try out the Scalatest plugin for Eclipse, which should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With