【问题标题】:How to find things and install them with Scala sbt?如何使用 Scala sbt 查找并安装它们?
【发布时间】:2020-08-03 02:46:20
【问题描述】:

我是 Scala 的新手,正在为 sbt 和安装东西而苦苦挣扎。例如:

我想在 Eclipse 中开发并因此使用 JUnit。根据:

http://www.scalatest.org/user_guide/using_junit_runner

“ScalaTest 包含一个 JUnit Runner”,但似乎并非如此。至少对我来说不是。 (当我尝试import org.scalatest.junit.JUnitRunner 时我得到object is not a member of package org.scalatestimport org.scalatest.flatspec.AnyFlatSpec 工作正常)

如何安装它?我查看了我的 sbt 文件,其中包含以下几行:

libraryDependencies += "org.scalactic" %% "scalactic" % "3.1.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.1" % "test"

并认为没问题,所以我需要 org.scalatest.junit 并尝试像这样添加它:

libraryDependencies += "org.scalatest" %% "junit" % "3.1.1" 

这当然给了我三个(!)屏幕:

Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.scalatest:junit_2.12:3.1.1
[error]   Not found

(为什么这么重复?只有一件事没找到,却抱怨了四次!)

我如何弄清楚如何安装这样的东西?现在我正在尝试一种猜测和随机谷歌搜索的组合方法,有时它有效,有时(就像现在)它对我来说失败了......

【问题讨论】:

    标签: scala junit sbt scalatest


    【解决方案1】:

    在 ScalaTest 3.1.x 中使用 JUnit runner 执行 ScalaTest 的套件,将以下依赖项添加到 build.sbt

    libraryDependencies ++= List(
      "org.scalatest"      %% "scalatest"           % "3.1.1"     % Test,
      "org.scalatestplus"  %% "scalatestplus-junit" % "1.0.0-M2"  % Test
    )
    

    并像这样注释套件

    import org.junit.runner.RunWith
    import org.scalatestplus.junit.JUnitRunner
    import org.scalatest.flatspec.AnyFlatSpec
    import org.scalatest.matchers.should.Matchers
    
    @RunWith(classOf[JUnitRunner])
    class HelloSpec extends AnyFlatSpec with Matchers {
      "The Hello object" should "say hello" in {
        Hello.greeting shouldEqual "hello"
      }
    }
    

    存在更新文档的未解决问题:Document how to use JUnitRunner in 3.x #1780

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      • 2011-11-28
      • 2013-09-30
      • 2015-10-24
      • 2016-06-07
      相关资源
      最近更新 更多