【问题标题】:Scala imported functions not found未找到 Scala 导入的函数
【发布时间】:2021-02-04 01:15:04
【问题描述】:

我最近开始使用 Scala,但在依赖项方面遇到了一些问题。我同时使用了 Maven 的 pom.xml 和 sbt build.sbt。

浏览 sbt 的参考手册我已经遇到了导入 scalatest 的问题。

我的项目文件夹中有 build.sbt,然后是 src/main/scala/Hello.scala 和 src/test/scala/HelloSpec.scala。

我的构建:

ThisBuild / scalaVersion := "2.13.3"
ThisBuild / organization := "com.example"

lazy val hello = (project in file("."))
    .settings(
        name := "Hello",
        libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.2" % Test,
    )

还有 HelloSpec.scala:

import org.scalatest._

class HelloSpec extends FunSuite with DiagrammedAssertions {
    test("Hello should start with H") {
        assert("hello".startsWith("H"))
    }
}

现在当我进入 sbt shell 并运行测试时,它提供了三个错误:

  • 未找到:输入 FunSuite
  • 未找到:输入 DiagrammedAssertions
  • 未找到:值测试

虽然我已经设置了我的环境变量(SCALA_HOME、JAVA_HOME),但奇怪的是Maven也发生了同样的事情(无法使用导入的函数)。

【问题讨论】:

标签: java scala maven sbt


【解决方案1】:

这对我来说是这样的

import org.scalatest.funsuite._
import org.scalatest.diagrams._

class HelloSpec extends AnyFunSuite with Diagrams {
  test("Hello should start with H") {
    assert("Hello".startsWith("H"))
  }
}

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 2020-04-08
    • 2020-03-19
    • 2015-07-02
    • 2021-12-29
    相关资源
    最近更新 更多