gpt4 book ai didi

scala - 为什么 sbt 说 "bad symbolic reference..."进行 ScalaTest 测试?

转载 作者:行者123 更新时间:2023-12-04 10:00:14 25 4
gpt4 key购买 nike

我开始使用 ScalaTest 和 sbt。 build.sbt 如下:

name := "MySpecSample"

version := "1.0"

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test"

scalaVersion := "2.10.3"

初始测试代码在这里。此测试代码单独运行,没有主要组件代码。
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()
}
}
}

我是按照 Official quick start写的.
但它不能正常工作。错误信息如下:
> test
[info] Compiling 1 Scala source to /Users/kaisasak/untitled/target/scala-2.10/test-classes...
[error] bad symbolic reference. A signature in package.class refers to type compileTimeOnly
[error] in package scala.annotation which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling package.class.
[error] /Users/kaisasak/untitled/src/test/scala/ExampleSpec.scala:6: Reference to class FlatSpec in package scalatest should not have survived past type checking,
[error] it should have been processed and eliminated during expansion of an enclosing macro.
[error] class ExampleSpec extends FlatSpec with Matchers {
[error] ^
[error] two errors found
[error] (test:compile) Compilation failed
[error] Total time: 3 s, completed Jun 29, 2014 11:20:41 AM

我可以在谷歌上找到同样的问题,但没有好的答案。
我的环境在这里。
  • MacOSX 10.9.3
  • 斯卡拉 2.10.3
  • sbt 0.13.2

  • 降级后用sbt 0.13.1试了一下,结果和0.13.2一样。我应该怎么做才能将 ScalaTest 与 sbt 一起使用?

    最佳答案

    在您的 build.sbt您使用以下内容将 Scala 的版本设置为 2.10.3:

    scalaVersion := "2.10.3" 

    然而 ScalaTest 依赖显式使用 Scala 2.11(注意 _2.11 部分):
    "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test"

    您必须对两者使用相同的主要 Scala 版本。

    使用 sbt,您可以简单地使用 %% 来确保这一点。而不是 %如下:
    "org.scalatest" %% "scalatest" % "2.2.0" % "test"

    关于scala - 为什么 sbt 说 "bad symbolic reference..."进行 ScalaTest 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24472645/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com