ScalaTest规范编译错误 [英] ScalaTest Spec Compilation Error

查看:250
本文介绍了ScalaTest规范编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Scala的新手,我正在尝试使用 ScalaTest 。我将build.sbt文件中的依赖项包含在
libraryDependencies ++ = Seq(
org.scalatest%scalatest_2.11%2.1.7%test

I am new to Scala and I am trying to use ScalaTest. I included its dependency in my build.sbt file as libraryDependencies++=Seq( "org.scalatest" % "scalatest_2.11" % "2.1.7" % "test" )

并刷新sbt,现在它出现在我的外部库文件夹中,所以我认为它已经正确安装。现在我想做一个测试类。所以我在src / test / scala下创建了一个。我使用ScalaTest网站的首页中的示例,它是

and refreshed sbt and now it appears in my External Libraries folder so I think it was installed correctly. Now I want to make a test class. So I created one under src/test/scala. I used the example from the ScalaTest website's frontpage which is

import collection.mutable.Stack
import org.scalatest._

class ExampleSpec extends FlatSpec with Matchers {

  "A Stack" should "pop values in last-in-first-out order" in {
    val stack = new Stack[Int]
    stack.push(1)
    stack.push(2)
    stack.pop() should be (2)
    stack.pop() should be (1)
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {
    val emptyStack = new Stack[Int]
    a [NoSuchElementException] should be thrownBy {
      emptyStack.pop()
    }
  }
}

但是,当我运行这个类时,我得到错误

However when I run this class I get the error

 Error:scalac: bad symbolic reference. A signature in package.class refers to type compileTimeOnly
in package scala.annotation which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.

 Error:(4, 27) Reference to class FlatSpec in package scalatest should not have survived past type checking,
it should have been processed and eliminated during expansion of an enclosing macro.
class ExampleSpec extends FlatSpec with Matchers {
                      ^

有人可以告诉我什么问题是。看起来它不是识别ScalaTest。然而,在我的外部图书馆和IntelliJ的自动完成也显示它在那里。在我开始使用ScalaTest之前,我是否需要刷新别的东西?

Could someone tell me what the problem is. It looks like it is not recognizing ScalaTest. However it is in my External Libraries and IntelliJ's auto-complete also shows that it is there. Do I somehow need to refresh something else before I can actually start using ScalaTest?

编辑:

我运行测试:编译从sbt我得到

  [error] error while loading package, class file needed by package is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading Matchers, class file needed by Matchers is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading Assertions, class file needed by Assertions is missing.
[error] reference value internal of package scala.reflect.macros refers to nonexisting symbol.
[error] error while loading AbstractSuite, class file needed by AbstractSuite is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading Tolerance, class file needed by Tolerance is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading BeWord, class file needed by BeWord is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading ResultOfNotWordForAny, class file needed by ResultOfNotWordForAny is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] error while loading NotWord, class file needed by NotWord is missing.
[error] reference value <init>$default$2 of object deprecated refers to nonexisting symbol.
[error] 8 errors found
[error] (test:compile) Compilation failed


推荐答案

似乎SBT试图针对scala 2.9.2进行编译。
我想你必须添加一个

It seems SBT tries to compile against scala 2.9.2. I guess you have to add one of

scalaVersion := "2.10.4"

scalaVersion := "2.11.1"

到您的 build.sbt

当然

libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.7" % "test"

此外,尝试最新的 SBT启动器

这篇关于ScalaTest规范编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆