Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse JUnit runner can't find ScalaTest methods on double click

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)
  }
}
like image 977
Jeff Axelrod Avatar asked Sep 21 '12 14:09

Jeff Axelrod


2 Answers

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

like image 107
Bill Venners Avatar answered Nov 12 '22 21:11

Bill Venners


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.

like image 23
Matthew Farwell Avatar answered Nov 12 '22 21:11

Matthew Farwell