ScalaTest 规范编译错误

2023-11-21

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

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

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

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

 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.

and also

 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 之前,我是否需要刷新其他内容?

EDIT:

还有当我跑步时test:compile从 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 进行编译。 我想你必须添加其中之一

scalaVersion := "2.10.4"

or

scalaVersion := "2.11.1"

to your build.sbt

而且当然

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

此外,您还可以尝试最新的SBT发射器.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ScalaTest 规范编译错误 的相关文章

随机推荐

  • 在 WebView 中从相机或图库上传图像

    此应用程序中的 WebView 打开一个带有上传按钮的页面 下面的代码块允许打开一个对话框以从图库或相机上传图像 在我的活动中 我有 private WebView wv make HTML upload button work in We
  • 一个干净的 CSS3 3 列布局,从哪里开始?

    我目前正在更新一个相当旧的网站 上次更新是在 2001 年左右 并同意使用 HTML5 和 CSS3 对于总体设计 我正在研究一种非常干净的白色和灰色色调风格 带有许多填充和边距 我的问题出在主页上 我想要一个 3 列居中布局 但从哪里开始
  • Python ctypes 加载错误:未定义的符号

    我试图使用 ctypes 将从 C 源代码编译的共享库加载到 Python 中 共享库 名为 库子库 下面 使用libusb图书馆 这就是 make 所做的 gcc c O2 Wall Werror g I src I boot vnd f
  • 从 CSV 文件中提取数据(融合表和 kml 解决方法)

    在使用 C 的 Android 版 Xamarin 谷歌地图中 您可以基于此创建多边形tutorial public void OnMapReady GoogleMap googleMap mMap googleMap PolylineOp
  • TransactionScope 无法与并行扩展一起使用?

    如果我执行以下操作 Using scope New TransactionScope entries Content ReadAs Of IList Of WebMaint AsParallel ForAll Sub entry repos
  • jquery推送制作多维数组

    我在没有帮助的情况下查看了其他类似的帖子 它们都是从已经制作的多维数组开始的 我想通过使用 push 神奇地制作一个 我的阵列 ItemsArray push RoomName RoomName Item this is where I w
  • 当数组长度不为空时出现“恐慌:运行时错误:索引超出范围”

    我很难学习如何在 Go 中循环字符串来做一些事情 具体来说 分隔单词而不是包含元音 我写了这个代码片段 https play golang org p zgDtOyq6qf 这是我运行时遇到的错误 panic runtime error i
  • 提高 LIKE 子句的性能

    这几天来 这一直是我头疼的事情 我之前创建数据库时对性能一无所知LIKE 我使用的查询是这样的 SELECT FROM JOINS WHERE tableA col1 LIKE keyword OR tableB col2 LIKE key
  • 隐藏拖动预览 - HTML 拖放

    我的一个网站具有拖放功能 一旦您开始拖动我的可拖动 div 之一 就会出现所拖动元素的透明预览 这实际上妨碍了我的用户准确放置元素的方式 因为他们拖动的内容并不直接反映删除的内容 有没有办法删除或更好地将拖动预览更改为不同的图像 我相信您可
  • 如何避免Python中的L

    gt gt gt sum range 49999951 50000000 2449998775L 有什么办法可以避免数字末尾的 L 吗 您正在查看数字的 Python 文字表示形式 它仅表明它是一个 Pythonlong整数 这个是正常的
  • 使用回收器视图的类似 Google Play 商店的界面

    我的任务是创建一个与 Google Play 商店非常相似的界面 会有一个类别名称 后面跟着 3 或 4 张卡片 水平 然后是 更多 按钮 然后再下一个类别 我已经使用将水平列表视图嵌套在垂直列表视图中来实现这一点 我知道 我可以通过使用具
  • 自动将多个对象映射到一个对象

    我有两个子类 我需要将列表元素复制到主对象中 public Class Foo1 Anote public bool Ison get set public List
  • 在javascript中对json对象进行排序

    例如有这样的代码 var json user1 id 3 user2 id 6 user3 id 1 我怎样才能将这个 json 排序为这样 var json user3 id 1 user1 id 3 user2 id 6 我用 ID 对
  • RabbitMQ虚拟主机启动服务时出错

    我的 RabbitMQ 服务器已经运行了几个月 今天早上我无法连接到它 我的应用程序超时并且管理客户端没有响应 重新启动机器 应用程序仍然超时 我可以登录管理客户端 但看到以下消息 虚拟主机 在节点rabbit MQT01上遇到错误 可能无
  • apache poi:将jtable保存到文件中

    我最近开始使用 java 当我需要从 jTable 开始创建 excel 文件时 我遇到了 apache poi 库的一些问题 我已经阅读了很多线程并提出了一些行不通的代码 即使这是非常简单的东西并且有很多例子 这让我看起来更愚蠢 我希望有
  • 为什么 Python 在使用绝对路径执行时不会退出引发的异常?

    已解决 重新启动机器似乎已解决该问题 如果问题再次出现 我会更新 我遇到一个问题Python2 6引发异常后挂起 特别是当foo py使用绝对路径调用 home user bar foo py 然后我需要ctrl c退出程序 如果从内部调用
  • 在 Spring Security 6 中使用两个或多个 SecurityFilterChains 无法正常工作,仅调用一个链 [重复]

    这个问题在这里已经有答案了 我很难找到我的两个SecurityFilterhain使用 Spring Security 6 相互协作 对于我的端点路径之一 v1 transactions 我希望用户使用 Oauth2 和其他端点路径进行授权
  • 无法加载文件或程序集 Microsoft.ServiceModel.DomainServices.Hosting

    我的本地环境中加载了一个应用程序 这是我继承的代码库 但根本没有让它工作 此时 当我在浏览器中导航到 http test myapp com 75 时 我收到以下错误 描述 处理服务此请求所需的配置文件期间发生错误 请查看下面的具体错误详细
  • 无法使用lombok构建maven jhipster项目

    mvnw 和 mvn clean install 在添加 lombok 依赖项时失败 但从 Intellij IDE 启动时成功运行 找到下面的错误 INFO ERROR COMPILATION ERROR INFO ERROR src m
  • ScalaTest 规范编译错误

    我是 Scala 新手 我正在尝试使用Scala测试 我将其依赖项包含在我的 build sbt 文件中libraryDependencies Seq org scalatest scalatest 2 11 2 1 7 test 并刷新了