0

I have an eclipse scala project which uses maven. Eclipse plugins for ScalaIDE and Scalatest are installed. I have tests like:

    import org.scalatest._

    class ExampleSpec extends FlatSpec with Matchers {
        feature("Feature A Test") {
            scenario("Foo scenario 1") {
              val a = FooClass().getResult()
              a.count shouldBe 1  // IDE shows error: value shouldBe is not a member of Long
              a(0).getString(0) shouldBe "FOO"  // IDE shows error: value shouldBe is not a member of String
            }
        }
    }

The maven compilation and the tests run fine, but in eclipse when I open this file, I see an error in eclipse wherever I am using a Matcher as mentioned in the comments above. Eg.

value shouldBe is not a member of Long

What am I missing? A scala test file shows hundreds of problems.

rgamber
  • 5,749
  • 10
  • 55
  • 99
  • How did you imported project into IDE? Is scalatest visible in "Java Build Path" -> "Libraries" -> "Maven container (or whatever it's called)"? Is Scala version in "Scala compiler" -> "Scala installation" the same as the one declared in POM? – MirMasej Mar 08 '17 at 08:56
  • It is indeed present under "Java build path - libraries- maven dependencies- scalatest". Yes Scala version is the same in both the places. – rgamber Mar 08 '17 at 16:51
  • Have you [mixed in matchers](http://www.scalatest.org/user_guide/using_matchers) in Spec? – MirMasej Mar 09 '17 at 18:10
  • I am using `MyClass extends FeatureSpec with BeforeAndAfterAll with Matchers`. What do you mean by "mixed in matchers", not sure I understand by looking at the link? – rgamber Mar 13 '17 at 18:28
  • Update: I am using `MyClass extends FeatureSpec with BeforeAndAfterAll with Matchers` with the `import org.scalatest.Matchers`. I am not using `import Matchers._`. – rgamber Mar 13 '17 at 18:40

2 Answers2

0

After adding the following dummy code:

case class Bar() {
    def count = Array(Bar())
    def getString(x: Int) = Array("aqq")
    def apply[T](x: Int) = this
}
case class FooClass() {
   def getResult() = Bar()
}

and changing FlatSpec to FeatureSpec as this is the syntax you are using in your ExampleSpec, the code compiles without any issues.

If it's still not the case for you I can suggest creating simple build.sbt and generating project with Eclipse sbt plugin.

MirMasej
  • 1,592
  • 12
  • 17
0

I know this is old, but I had the same issue with eclipse (late 2018), and I was able to fix this by making sure the test was NOT in the default package. That is, add "package org.scalatest.examples.flatspec" to the beginning of your test, as an example, and move the test into that package.