2017-03-07 32 views
0

我有一個使用maven的eclipse scala項目。安裝了ScalaIDE和Scalatest的Eclipse插件。我有這樣的測試:Scalatest在使用Matcher時顯示錯誤

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 
      } 
     } 
    } 

Maven的編譯和測試運行正常,但在Eclipse,當我打開這個文件,我看到日食的錯誤無論我使用的是Matcher如上在評論中提到。例如。

value shouldBe is not a member of Long 

我在想什麼?一個scala測試文件顯示了數百個問題。

+0

您是如何將項目導入IDE的?在「Java Build Path」 - >「Libraries」 - >「Maven容器(或其他名稱)」中可以看到scalatest? 「Scala編譯器」 - >「Scala安裝」中的Scala版本與POM中聲明的版本相同嗎? – MirMasej

+0

它確實出現在「Java構建路徑 - 庫 - maven依賴關係 - scalatest」下。是的,Scala版本在這兩個地方都是一樣的。 – rgamber

+0

你有沒有[在匹配器中混合](http://www.scalatest.org/user_guide/using_matchers)在Spec? – MirMasej

回答

0

添加以下啞代碼後:

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() 
} 

,改變FlatSpecFeatureSpec,因爲這是the syntax你正在使用你的ExampleSpec,代碼編譯沒有任何問題。

如果仍然不適合您,我可以建議創建簡單的build.sbt並使用Eclipse sbt plugin生成項目。