2017-03-07 68 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生成项目。